Date processing cleanup.
This commit is contained in:
parent
9721ed3cc9
commit
71b4db8e10
@ -19,7 +19,7 @@ import {
|
|||||||
getISOWeek,
|
getISOWeek,
|
||||||
} from '@/utils/date'
|
} from '@/utils/date'
|
||||||
import { toLocalString, fromLocalString, DEFAULT_TZ } from '@/utils/date'
|
import { toLocalString, fromLocalString, DEFAULT_TZ } from '@/utils/date'
|
||||||
import { addDays, differenceInCalendarDays } from 'date-fns'
|
import { addDays, differenceInCalendarDays, differenceInWeeks } from 'date-fns'
|
||||||
import { getHolidayForDate } from '@/utils/holidays'
|
import { getHolidayForDate } from '@/utils/holidays'
|
||||||
|
|
||||||
const calendarStore = useCalendarStore()
|
const calendarStore = useCalendarStore()
|
||||||
@ -52,20 +52,18 @@ const lastTapTime = ref(0)
|
|||||||
const lastTapDate = ref(null)
|
const lastTapDate = ref(null)
|
||||||
const DOUBLE_TAP_DELAY = 300 // milliseconds
|
const DOUBLE_TAP_DELAY = 300 // milliseconds
|
||||||
|
|
||||||
const WEEK_MS = 7 * 24 * 60 * 60 * 1000
|
|
||||||
|
|
||||||
const minVirtualWeek = computed(() => {
|
const minVirtualWeek = computed(() => {
|
||||||
const date = new Date(calendarStore.minYear, 0, 1)
|
const date = new Date(calendarStore.minYear, 0, 1)
|
||||||
const dayOffset = (date.getDay() - calendarStore.config.first_day + 7) % 7
|
const dayOffset = (date.getDay() - calendarStore.config.first_day + 7) % 7
|
||||||
const firstDayOfWeek = addDays(date, -dayOffset)
|
const firstDayOfWeek = addDays(date, -dayOffset)
|
||||||
return Math.floor((firstDayOfWeek.getTime() - baseDate.value.getTime()) / WEEK_MS)
|
return differenceInWeeks(firstDayOfWeek, baseDate.value)
|
||||||
})
|
})
|
||||||
|
|
||||||
const maxVirtualWeek = computed(() => {
|
const maxVirtualWeek = computed(() => {
|
||||||
const date = new Date(calendarStore.maxYear, 11, 31)
|
const date = new Date(calendarStore.maxYear, 11, 31)
|
||||||
const dayOffset = (date.getDay() - calendarStore.config.first_day + 7) % 7
|
const dayOffset = (date.getDay() - calendarStore.config.first_day + 7) % 7
|
||||||
const firstDayOfWeek = addDays(date, -dayOffset)
|
const firstDayOfWeek = addDays(date, -dayOffset)
|
||||||
return Math.floor((firstDayOfWeek.getTime() - baseDate.value.getTime()) / WEEK_MS)
|
return differenceInWeeks(firstDayOfWeek, baseDate.value)
|
||||||
})
|
})
|
||||||
|
|
||||||
const totalVirtualWeeks = computed(() => {
|
const totalVirtualWeeks = computed(() => {
|
||||||
@ -127,7 +125,7 @@ function computeRowHeight() {
|
|||||||
function getWeekIndex(date) {
|
function getWeekIndex(date) {
|
||||||
const dayOffset = (date.getDay() - calendarStore.config.first_day + 7) % 7
|
const dayOffset = (date.getDay() - calendarStore.config.first_day + 7) % 7
|
||||||
const firstDayOfWeek = addDays(date, -dayOffset)
|
const firstDayOfWeek = addDays(date, -dayOffset)
|
||||||
return Math.floor((firstDayOfWeek.getTime() - baseDate.value.getTime()) / WEEK_MS)
|
return differenceInWeeks(firstDayOfWeek, baseDate.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFirstDayForVirtualWeek(virtualWeek) {
|
function getFirstDayForVirtualWeek(virtualWeek) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user