@@ -62,9 +62,9 @@ import type { CoreContext, CoreInternalContext } from './context'
62
62
* datetime(context, value, { key: 'short', part: true })
63
63
*
64
64
* // orverride context.datetimeFormats[locale] options with functino options
65
- * datetime(cnotext, value, 'short', { currency : 'EUR ' })
66
- * datetime(cnotext, value, 'short', 'ja-JP', { currency : 'EUR ' })
67
- * datetime(context, value, { key: 'short', part: true }, { currency : 'EUR' })
65
+ * datetime(cnotext, value, 'short', { year : '2-digit ' })
66
+ * datetime(cnotext, value, 'short', 'ja-JP', { year : '2-digit ' })
67
+ * datetime(context, value, { key: 'short', part: true, year : '2-digit' })
68
68
*/
69
69
70
70
/**
@@ -75,7 +75,8 @@ import type { CoreContext, CoreInternalContext } from './context'
75
75
*
76
76
* @VueI 18nGeneral
77
77
*/
78
- export interface DateTimeOptions < Key = string , Locales = Locale > {
78
+ export interface DateTimeOptions < Key = string , Locales = Locale >
79
+ extends Intl . DateTimeFormatOptions {
79
80
/**
80
81
* @remarks
81
82
* The target format key
@@ -295,12 +296,35 @@ export function datetime<
295
296
return ! part ? formatter . format ( value ) : formatter . formatToParts ( value )
296
297
}
297
298
299
+ const DATETIME_FORMAT_OPTIONS_KEYS = [
300
+ 'localeMatcher' ,
301
+ 'weekday' ,
302
+ 'era' ,
303
+ 'year' ,
304
+ 'month' ,
305
+ 'day' ,
306
+ 'hour' ,
307
+ 'minute' ,
308
+ 'second' ,
309
+ 'timeZoneName' ,
310
+ 'formatMatcher' ,
311
+ 'hour12' ,
312
+ 'timeZone' ,
313
+ 'dateStyle' ,
314
+ 'timeStyle' ,
315
+ 'calendar' ,
316
+ 'dayPeriod' ,
317
+ 'numberingSystem' ,
318
+ 'hourCycle' ,
319
+ 'fractionalSecondDigits'
320
+ ]
321
+
298
322
/** @internal */
299
323
export function parseDateTimeArgs (
300
324
...args : unknown [ ]
301
325
) : [ string , number | Date , DateTimeOptions , Intl . DateTimeFormatOptions ] {
302
326
const [ arg1 , arg2 , arg3 , arg4 ] = args
303
- let options = { } as DateTimeOptions
327
+ const options = { } as DateTimeOptions
304
328
let overrides = { } as Intl . DateTimeFormatOptions
305
329
306
330
let value : number | Date
@@ -340,7 +364,15 @@ export function parseDateTimeArgs(
340
364
if ( isString ( arg2 ) ) {
341
365
options . key = arg2
342
366
} else if ( isPlainObject ( arg2 ) ) {
343
- options = arg2
367
+ Object . keys ( arg2 ) . forEach ( key => {
368
+ if ( DATETIME_FORMAT_OPTIONS_KEYS . includes ( key ) ) {
369
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
370
+ ; ( overrides as any ) [ key ] = ( arg2 as any ) [ key ]
371
+ } else {
372
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
373
+ ; ( options as any ) [ key ] = ( arg2 as any ) [ key ]
374
+ }
375
+ } )
344
376
}
345
377
346
378
if ( isString ( arg3 ) ) {
0 commit comments