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

Fixed date format by adding leading zeros. #335

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion components/BlogPostCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<img alt="Blog post image" :src="post.image || 'https://cryptic-game.net/open-graph.jpg'" :style="imageStyle" class="blog-post-card__image">
<div class="blog-post-card__info">
<span class="blog-post-card__title">{{ post.title }}</span>
<small class="blog-post-card__date">{{ new Date(post.created).toLocaleDateString() }}</small>
<small class="blog-post-card__date">{{ getDateWithLZero(Intl.DateTimeFormat().format(new Date(post.created))) }}</small>
<span>{{ post.description }}</span>
<div class="blog-post-card__footer">
<nuxt-link :to="localePath(`/blog/${post.id.postId}`)" class="blog-post-card__link link">
Expand All @@ -15,8 +15,10 @@
</template>

<script>
import DateUtils from '../mixins/DateUtils.js'
export default {
name: 'BlogPostCard',
mixins: [DateUtils],
props: {
post: {
type: Object,
Expand Down
23 changes: 23 additions & 0 deletions mixins/DateUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export default {
methods: {
getDateWithLZero (date) {
// eslint-disable-next-line prefer-const
let dateA = []
let s = false
if (date.includes('.')) { dateA = date.split('.') } else if (date.includes('/')) { dateA = date.split('/'); s = true }

if (dateA[0].length === 1) {
dateA[0] = '0' + dateA[0]
}
if (dateA[1].length === 1) {
dateA[1] = '0' + dateA[1]
}
if (!s) {
return dateA.join('.')
} else {
return dateA.join('/')
}
}

}
}
5 changes: 3 additions & 2 deletions pages/blog/_slug.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<NavigationBar title="Blog" />
<article class="content formatted">
<img :alt="`Title Image from: ${post.title}`" :src="post.image" class="post-page__image"><br>
<span>{{ Intl.DateTimeFormat($i18n.localeProperties.iso).format(new Date(post.created)) }}</span>
<span>{{ getDateWithLZero(Intl.DateTimeFormat($i18n.localeProperties.iso).format(new Date(post.created))).toString() }}</span>
<h2 class="post-page__title">
{{ post.title || "untitled post" }}
</h2>
Expand All @@ -16,11 +16,12 @@
</template>

<script>
import DateUtils from '../../mixins/DateUtils.js'
import NavigationBar from '@/components/NavigationBar'

export default {
name: 'PostPage',
components: { NavigationBar },
mixins: [DateUtils],
asyncData ({ route }) {
return { slug: route.params.slug }
},
Expand Down
4 changes: 3 additions & 1 deletion pages/changelog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div>
<h3>{{ change.name }}</h3>
<client-only>
<small>{{ getPrettyDate(change.date) }}</small>
<small>{{ getDateWithLZero(getPrettyDate(change.date)) }}</small>
</client-only>
<div />
<div v-if="change.additions" class="additions">
Expand Down Expand Up @@ -63,11 +63,13 @@

<script>
import NavigationBar from '@/components/NavigationBar'
import DateUtils from '@/mixins/DateUtils'
export default {
name: 'ChangelogPage',
components: {
NavigationBar
},
mixins: [DateUtils],
data () {
return {
changes: []
Expand Down