Skip to content

Commit

Permalink
fix(VDatePicker): crash with date multiple and external adapter (vuet…
Browse files Browse the repository at this point in the history
…ifyjs#19336)

fixes vuetifyjs#19330

Co-authored-by: Son Tran <stt@cct-technology.com>
  • Loading branch information
2 people authored and VIXI0 committed Mar 13, 2024
1 parent 9941d90 commit 05141ae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const VDatePickerMonth = genericComponent<VDatePickerMonthSlots>()({
rangeStop.value = _value
}

const diff = adapter.getDiff(rangeStop.value, rangeStart.value)
const diff = adapter.getDiff(rangeStop.value, rangeStart.value, 'days')
const datesInRange = [rangeStart.value]

for (let i = 1; i < diff; i++) {
Expand Down
24 changes: 20 additions & 4 deletions packages/vuetify/src/composables/date/adapters/vuetify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,27 @@ function getDiff (date: Date, comparing: Date | string, unit?: string) {
const d = new Date(date)
const c = new Date(comparing)

if (unit === 'month') {
return d.getMonth() - c.getMonth() + (d.getFullYear() - c.getFullYear()) * 12
switch (unit) {
case 'years':
return d.getFullYear() - c.getFullYear()
case 'quarters':
return Math.floor((d.getMonth() - c.getMonth() + (d.getFullYear() - c.getFullYear()) * 12) / 4)
case 'months':
return d.getMonth() - c.getMonth() + (d.getFullYear() - c.getFullYear()) * 12
case 'weeks':
return Math.floor((d.getTime() - c.getTime()) / (1000 * 60 * 60 * 24 * 7))
case 'days':
return Math.floor((d.getTime() - c.getTime()) / (1000 * 60 * 60 * 24))
case 'hours':
return Math.floor((d.getTime() - c.getTime()) / (1000 * 60 * 60))
case 'minutes':
return Math.floor((d.getTime() - c.getTime()) / (1000 * 60))
case 'seconds':
return Math.floor((d.getTime() - c.getTime()) / 1000)
default: {
return d.getTime() - c.getTime()
}
}

return Math.floor((d.getTime() - c.getTime()) / (1000 * 60 * 60 * 24))
}

function setHours (date: Date, count: number) {
Expand Down

0 comments on commit 05141ae

Please sign in to comment.