Skip to content

Commit 98003f2

Browse files
authored
fix(DateAdapter): update date formats to match interface (#20229)
fixes #20228
1 parent 389be09 commit 98003f2

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

packages/vuetify/src/composables/date/adapters/__tests__/vuetify.spec.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,23 @@ describe('vuetify date adapter', () => {
1717
})
1818

1919
it('formats dates', () => {
20-
let instance = new VuetifyDateAdapter({ locale: 'en-us' })
20+
let instance = new VuetifyDateAdapter({ locale: 'en-gb' })
21+
expect(instance.format(new Date(2000, 0, 1, 13), 'fullTime')).toBe('13:00')
22+
23+
instance = new VuetifyDateAdapter({ locale: 'en-us' })
24+
expect(instance.format(new Date(2000, 0, 1, 13), 'fullTime')).toBe('1:00 PM')
25+
expect(instance.format(new Date(2000, 0, 1, 13), 'fullTime12h')).toBe('1:00 PM')
26+
expect(instance.format(new Date(2000, 0, 1, 13), 'fullTime24h')).toBe('13:00')
27+
28+
// These don't match the date-io spec
29+
expect(instance.format(new Date(2000, 0, 1, 13), 'fullDateTime')).toBe('Jan 1, 2000, 1:00 PM')
30+
expect(instance.format(new Date(2000, 0, 1, 13), 'fullDateTime12h')).toBe('Jan 1, 2000, 1:00 PM')
31+
expect(instance.format(new Date(2000, 0, 1, 13), 'fullDateTime24h')).toBe('Jan 1, 2000, 13:00')
32+
33+
const keyboardDateTime12hFormat = '01/01/2000 1:00 PM'
34+
expect(instance.format(new Date(2000, 0, 1, 13), 'keyboardDateTime')).toBe(keyboardDateTime12hFormat)
35+
expect(instance.format(new Date(2000, 0, 1, 13), 'keyboardDateTime12h')).toBe(keyboardDateTime12hFormat)
36+
expect(instance.format(new Date(2000, 0, 1, 13), 'keyboardDateTime24h')).toBe('01/01/2000 13:00')
2137

2238
expect(instance.format(new Date(2000, 0, 1), 'fullDateWithWeekday')).toBe('Saturday, January 1, 2000')
2339

packages/vuetify/src/composables/date/adapters/vuetify.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -336,35 +336,35 @@ function format (
336336
options = { second: 'numeric' }
337337
break
338338
case 'fullTime':
339-
options = { hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: true }
339+
options = { hour: 'numeric', minute: 'numeric' }
340340
break
341341
case 'fullTime12h':
342-
options = { hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: true }
342+
options = { hour: 'numeric', minute: 'numeric', hour12: true }
343343
break
344344
case 'fullTime24h':
345-
options = { hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: false }
345+
options = { hour: 'numeric', minute: 'numeric', hour12: false }
346346
break
347347
case 'fullDateTime':
348-
options = { year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: true }
348+
options = { year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric' }
349349
break
350350
case 'fullDateTime12h':
351-
options = { year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: true }
351+
options = { year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric', hour12: true }
352352
break
353353
case 'fullDateTime24h':
354-
options = { year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: false }
354+
options = { year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric', hour12: false }
355355
break
356356
case 'keyboardDate':
357357
options = { year: 'numeric', month: '2-digit', day: '2-digit' }
358358
break
359359
case 'keyboardDateTime':
360-
options = { year: 'numeric', month: '2-digit', day: '2-digit', hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: false }
361-
break
360+
options = { year: 'numeric', month: '2-digit', day: '2-digit', hour: 'numeric', minute: 'numeric' }
361+
return new Intl.DateTimeFormat(locale, options).format(newDate).replace(/, /g, ' ')
362362
case 'keyboardDateTime12h':
363-
options = { year: 'numeric', month: '2-digit', day: '2-digit', hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: true }
364-
break
363+
options = { year: 'numeric', month: '2-digit', day: '2-digit', hour: 'numeric', minute: 'numeric', hour12: true }
364+
return new Intl.DateTimeFormat(locale, options).format(newDate).replace(/, /g, ' ')
365365
case 'keyboardDateTime24h':
366-
options = { year: 'numeric', month: '2-digit', day: '2-digit', hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: false }
367-
break
366+
options = { year: 'numeric', month: '2-digit', day: '2-digit', hour: 'numeric', minute: 'numeric', hour12: false }
367+
return new Intl.DateTimeFormat(locale, options).format(newDate).replace(/, /g, ' ')
368368
default:
369369
options = customFormat ?? { timeZone: 'UTC', timeZoneName: 'short' }
370370
}

0 commit comments

Comments
 (0)