Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit 6acb9e0

Browse files
committed
fix: inconsistent date in different timezone (fix #97)
1 parent fd6d7ac commit 6acb9e0

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

components/PostMeta.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@
2525

2626
<script>
2727
import dayjs from 'dayjs'
28+
import dayjsPluginUTC from 'dayjs/plugin/utc'
2829
import { NavigationIcon, ClockIcon } from 'vue-feather-icons'
2930
import PostTag from './PostTag.vue'
3031
32+
dayjs.extend(dayjsPluginUTC)
33+
3134
export default {
3235
name: 'PostMeta',
3336
components: { NavigationIcon, ClockIcon, PostTag },
@@ -47,9 +50,9 @@ export default {
4750
},
4851
computed: {
4952
resolvedDate() {
50-
return dayjs(this.date).format(
51-
this.$themeConfig.dateFormat || 'ddd MMM DD YYYY'
52-
)
53+
return dayjs
54+
.utc(this.date)
55+
.format(this.$themeConfig.dateFormat || 'ddd MMM DD YYYY')
5356
},
5457
resolvedTags() {
5558
if (!this.tags || Array.isArray(this.tags)) return this.tags

global-components/BaseListLayout.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,15 @@
8484
8585
import Vue from 'vue'
8686
import dayjs from 'dayjs'
87+
import dayjsPluginUTC from 'dayjs/plugin/utc'
8788
import { NavigationIcon, ClockIcon, TagIcon } from 'vue-feather-icons'
8889
import {
8990
Pagination,
9091
SimplePagination,
9192
} from '@vuepress/plugin-blog/lib/client/components'
9293
94+
dayjs.extend(dayjsPluginUTC)
95+
9396
export default {
9497
components: { NavigationIcon, ClockIcon, TagIcon },
9598
@@ -124,9 +127,9 @@ export default {
124127
},
125128
126129
resolvePostDate(date) {
127-
return dayjs(date).format(
128-
this.$themeConfig.dateFormat || 'ddd MMM DD YYYY'
129-
)
130+
return dayjs
131+
.utc(date)
132+
.format(this.$themeConfig.dateFormat || 'ddd MMM DD YYYY')
130133
},
131134
132135
resolvePostTags(tags) {

0 commit comments

Comments
 (0)