@@ -16,16 +16,7 @@ import {
16
16
TIME_ZONE
17
17
} from './slots' ;
18
18
import { Temporal , Intl } from '..' ;
19
- import {
20
- DateTimeFormatParams as Params ,
21
- DateTimeFormatReturn as Return ,
22
- InstantParams ,
23
- PlainDateParams ,
24
- PlainDateTimeParams ,
25
- PlainMonthDayParams ,
26
- PlainTimeParams ,
27
- PlainYearMonthParams
28
- } from './internaltypes' ;
19
+ import { DateTimeFormatParams as Params , DateTimeFormatReturn as Return } from './internaltypes' ;
29
20
30
21
const DATE = Symbol ( 'date' ) ;
31
22
const YM = Symbol ( 'ym' ) ;
@@ -340,7 +331,9 @@ function amend(optionsParam: Intl.DateTimeFormatOptions = {}, amended: MaybeFals
340
331
return options as globalThis . Intl . DateTimeFormatOptions ;
341
332
}
342
333
343
- function timeAmend ( optionsParam : Intl . DateTimeFormatOptions ) {
334
+ type OptionsType < T extends TypesWithToLocaleString > = NonNullable < Parameters < T [ 'toLocaleString' ] > [ 1 ] > ;
335
+
336
+ function timeAmend ( optionsParam : OptionsType < Temporal . PlainTime > ) {
344
337
let options = amend ( optionsParam , {
345
338
year : false ,
346
339
month : false ,
@@ -359,7 +352,7 @@ function timeAmend(optionsParam: Intl.DateTimeFormatOptions) {
359
352
return options ;
360
353
}
361
354
362
- function yearMonthAmend ( optionsParam : PlainYearMonthParams [ 'toLocaleString' ] [ 1 ] ) {
355
+ function yearMonthAmend ( optionsParam : OptionsType < Temporal . PlainYearMonth > ) {
363
356
let options = amend ( optionsParam , {
364
357
day : false ,
365
358
hour : false ,
@@ -377,7 +370,7 @@ function yearMonthAmend(optionsParam: PlainYearMonthParams['toLocaleString'][1])
377
370
return options ;
378
371
}
379
372
380
- function monthDayAmend ( optionsParam : PlainMonthDayParams [ 'toLocaleString' ] [ 1 ] ) {
373
+ function monthDayAmend ( optionsParam : OptionsType < Temporal . PlainMonthDay > ) {
381
374
let options = amend ( optionsParam , {
382
375
year : false ,
383
376
hour : false ,
@@ -395,7 +388,7 @@ function monthDayAmend(optionsParam: PlainMonthDayParams['toLocaleString'][1]) {
395
388
return options ;
396
389
}
397
390
398
- function dateAmend ( optionsParam : PlainDateParams [ 'toLocaleString' ] [ 1 ] ) {
391
+ function dateAmend ( optionsParam : OptionsType < Temporal . PlainDate > ) {
399
392
let options = amend ( optionsParam , {
400
393
hour : false ,
401
394
minute : false ,
@@ -414,7 +407,7 @@ function dateAmend(optionsParam: PlainDateParams['toLocaleString'][1]) {
414
407
return options ;
415
408
}
416
409
417
- function datetimeAmend ( optionsParam : PlainDateTimeParams [ 'toLocaleString' ] [ 1 ] ) {
410
+ function datetimeAmend ( optionsParam : OptionsType < Temporal . PlainDateTime > ) {
418
411
let options = amend ( optionsParam , { timeZoneName : false } ) ;
419
412
if ( ! hasTimeOptions ( options ) && ! hasDateOptions ( options ) ) {
420
413
options = ObjectAssign ( { } , options , {
@@ -429,7 +422,7 @@ function datetimeAmend(optionsParam: PlainDateTimeParams['toLocaleString'][1]) {
429
422
return options ;
430
423
}
431
424
432
- function zonedDateTimeAmend ( optionsParam : PlainTimeParams [ 'toLocaleString' ] [ 1 ] ) {
425
+ function zonedDateTimeAmend ( optionsParam : OptionsType < Temporal . PlainTime > ) {
433
426
let options = optionsParam ;
434
427
if ( ! hasTimeOptions ( options ) && ! hasDateOptions ( options ) ) {
435
428
options = ObjectAssign ( { } , options , {
@@ -445,7 +438,7 @@ function zonedDateTimeAmend(optionsParam: PlainTimeParams['toLocaleString'][1])
445
438
return options ;
446
439
}
447
440
448
- function instantAmend ( optionsParam : InstantParams [ 'toLocaleString' ] [ 1 ] ) {
441
+ function instantAmend ( optionsParam : OptionsType < Temporal . Instant > ) {
449
442
let options = optionsParam ;
450
443
if ( ! hasTimeOptions ( options ) && ! hasDateOptions ( options ) ) {
451
444
options = ObjectAssign ( { } , options , {
@@ -460,11 +453,11 @@ function instantAmend(optionsParam: InstantParams['toLocaleString'][1]) {
460
453
return options ;
461
454
}
462
455
463
- function hasDateOptions ( options : Parameters < TypesWithToLocaleString [ 'toLocaleString' ] > [ 1 ] ) {
456
+ function hasDateOptions ( options : OptionsType < TypesWithToLocaleString > ) {
464
457
return 'year' in options || 'month' in options || 'day' in options || 'weekday' in options || 'dateStyle' in options ;
465
458
}
466
459
467
- function hasTimeOptions ( options : Parameters < TypesWithToLocaleString [ 'toLocaleString' ] > [ 1 ] ) {
460
+ function hasTimeOptions ( options : OptionsType < TypesWithToLocaleString > ) {
468
461
return (
469
462
'hour' in options || 'minute' in options || 'second' in options || 'timeStyle' in options || 'dayPeriod' in options
470
463
) ;
@@ -509,7 +502,8 @@ type TypesWithToLocaleString =
509
502
| Temporal . PlainTime
510
503
| Temporal . PlainYearMonth
511
504
| Temporal . PlainMonthDay
512
- | Temporal . ZonedDateTime ;
505
+ | Temporal . ZonedDateTime
506
+ | Temporal . Instant ;
513
507
514
508
function extractOverrides ( temporalObj : Params [ 'format' ] [ 0 ] , main : DateTimeFormatImpl ) {
515
509
const DateTime = GetIntrinsic ( '%Temporal.PlainDateTime%' ) ;
0 commit comments