Skip to content

Commit

Permalink
fix: timezone in VCLiveTime & time_warning, close #341
Browse files Browse the repository at this point in the history
  • Loading branch information
YunYouJun committed Feb 10, 2024
1 parent 55293d9 commit 5668599
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
18 changes: 8 additions & 10 deletions packages/valaxy-addon-components/components/VCLiveTime.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import dayjs from 'dayjs'
const props = defineProps<{
startTime: string
Expand All @@ -17,16 +18,13 @@ const passSecond = ref(0)
* get live time
*/
function siteLiveTime() {
const start = new Date(props.startTime)
const now = new Date()
const timeDiff = (now.getTime() - start.getTime())
const msPerMinute = 60 * 1000
const msPerHour = 60 * msPerMinute
const msPerDay = 24 * msPerHour
passDay.value = Math.floor(timeDiff / msPerDay)
passHour.value = Math.floor((timeDiff % msPerDay) / 60 / 60 / 1000)
passMinute.value = Math.floor((timeDiff % msPerHour) / 60 / 1000)
passSecond.value = Math.floor((timeDiff % msPerMinute) / 1000)
const start = dayjs(props.startTime)
const now = dayjs()
const timeDiff = now.diff(start)
passDay.value = Math.floor(timeDiff / 1000 / 60 / 60 / 24)
passHour.value = Math.floor(timeDiff / 1000 / 60 / 60 % 24)
passMinute.value = Math.floor(timeDiff / 1000 / 60 % 60)
passSecond.value = Math.floor(timeDiff / 1000 % 60)
}
onMounted(() => {
Expand Down
6 changes: 6 additions & 0 deletions packages/valaxy-theme-yun/setup/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { defineAppSetup } from 'valaxy'

import dayjs from 'dayjs'
import timezone from 'dayjs/plugin/timezone'

export default defineAppSetup((_ctx) => {
// can do for setup

// for types in time warning
dayjs.extend(timezone)
})
6 changes: 0 additions & 6 deletions packages/valaxy/client/utils/time.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc'
import timezone from 'dayjs/plugin/timezone'

import type { Post } from '../../types'

dayjs.extend(utc)
dayjs.extend(timezone)

/**
* use dayjs format date
* @param date
Expand Down

0 comments on commit 5668599

Please sign in to comment.