Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Commit

Permalink
feat: util functions, format date and time
Browse files Browse the repository at this point in the history
  • Loading branch information
ocjojo committed Mar 22, 2020
1 parent 8cef163 commit cfa68de
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
22 changes: 22 additions & 0 deletions frontend/src/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export function slugify(name) {
return name
.toString()
.toLowerCase()
.trim()
.replace(/&/g, "-and-") // Replace & with 'and'
.replace(/[\s\W-]+/g, "-")
.replace(/-$/, ""); // Remove last floating dash if exists
}

export function formatDate(date) {
return new Date(Date.parse(date)).toLocaleDateString();
}

export function formatTime(time) {
return new Date(Date.parse(time)).toLocaleTimeString();
}

export function formatDatetime(datetime) {
const date = new Date(Date.parse(datetime));
return date.toLocaleDateString() + " " + date.toLocaleTimeString();
}
4 changes: 3 additions & 1 deletion frontend/src/views/Room.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<div>{{ message.AuthorID }}</div>
</div>
<div class="post-container">
<div class="time">{{ message.CreatedAt }}</div>
<div class="time">{{ formatDatetime(message.CreatedAt) }}</div>
{{ message.Message }}
</div>
</div>
Expand All @@ -35,6 +35,7 @@

<script>
import { mapGetters } from "@/store";
import { formatDatetime } from "@/util";
export default {
data() {
return {
Expand All @@ -43,6 +44,7 @@ export default {
};
},
methods: {
formatDatetime,
getData(routeName) {
const getters = mapGetters(["room", "roomMessages"]);
const id = routeName.split("-", 2)[0];
Expand Down
9 changes: 2 additions & 7 deletions frontend/src/views/Tracks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<script>
import TrackCard from "@/components/TrackCard";
import { mapGetters } from "@/store";
import { slugify } from "@/util";
export default {
components: {
Expand All @@ -53,13 +54,7 @@ export default {
},
methods: {
getRouterString(item) {
return item
.toString()
.toLowerCase()
.trim()
.replace(/&/g, "-and-") // Replace & with 'and'
.replace(/[\s\W-]+/g, "-")
.replace(/-$/, ""); // Remove last floating dash if exists
return slugify(item);
}
}
};
Expand Down

0 comments on commit cfa68de

Please sign in to comment.