@@ -16,16 +16,7 @@ import {
1616 TIME_ZONE
1717} from './slots' ;
1818import { 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' ;
2920
3021const DATE = Symbol ( 'date' ) ;
3122const YM = Symbol ( 'ym' ) ;
@@ -340,7 +331,9 @@ function amend(optionsParam: Intl.DateTimeFormatOptions = {}, amended: MaybeFals
340331 return options as globalThis . Intl . DateTimeFormatOptions ;
341332}
342333
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 > ) {
344337 let options = amend ( optionsParam , {
345338 year : false ,
346339 month : false ,
@@ -359,7 +352,7 @@ function timeAmend(optionsParam: Intl.DateTimeFormatOptions) {
359352 return options ;
360353}
361354
362- function yearMonthAmend ( optionsParam : PlainYearMonthParams [ 'toLocaleString' ] [ 1 ] ) {
355+ function yearMonthAmend ( optionsParam : OptionsType < Temporal . PlainYearMonth > ) {
363356 let options = amend ( optionsParam , {
364357 day : false ,
365358 hour : false ,
@@ -377,7 +370,7 @@ function yearMonthAmend(optionsParam: PlainYearMonthParams['toLocaleString'][1])
377370 return options ;
378371}
379372
380- function monthDayAmend ( optionsParam : PlainMonthDayParams [ 'toLocaleString' ] [ 1 ] ) {
373+ function monthDayAmend ( optionsParam : OptionsType < Temporal . PlainMonthDay > ) {
381374 let options = amend ( optionsParam , {
382375 year : false ,
383376 hour : false ,
@@ -395,7 +388,7 @@ function monthDayAmend(optionsParam: PlainMonthDayParams['toLocaleString'][1]) {
395388 return options ;
396389}
397390
398- function dateAmend ( optionsParam : PlainDateParams [ 'toLocaleString' ] [ 1 ] ) {
391+ function dateAmend ( optionsParam : OptionsType < Temporal . PlainDate > ) {
399392 let options = amend ( optionsParam , {
400393 hour : false ,
401394 minute : false ,
@@ -414,7 +407,7 @@ function dateAmend(optionsParam: PlainDateParams['toLocaleString'][1]) {
414407 return options ;
415408}
416409
417- function datetimeAmend ( optionsParam : PlainDateTimeParams [ 'toLocaleString' ] [ 1 ] ) {
410+ function datetimeAmend ( optionsParam : OptionsType < Temporal . PlainDateTime > ) {
418411 let options = amend ( optionsParam , { timeZoneName : false } ) ;
419412 if ( ! hasTimeOptions ( options ) && ! hasDateOptions ( options ) ) {
420413 options = ObjectAssign ( { } , options , {
@@ -429,7 +422,7 @@ function datetimeAmend(optionsParam: PlainDateTimeParams['toLocaleString'][1]) {
429422 return options ;
430423}
431424
432- function zonedDateTimeAmend ( optionsParam : PlainTimeParams [ 'toLocaleString' ] [ 1 ] ) {
425+ function zonedDateTimeAmend ( optionsParam : OptionsType < Temporal . PlainTime > ) {
433426 let options = optionsParam ;
434427 if ( ! hasTimeOptions ( options ) && ! hasDateOptions ( options ) ) {
435428 options = ObjectAssign ( { } , options , {
@@ -445,7 +438,7 @@ function zonedDateTimeAmend(optionsParam: PlainTimeParams['toLocaleString'][1])
445438 return options ;
446439}
447440
448- function instantAmend ( optionsParam : InstantParams [ 'toLocaleString' ] [ 1 ] ) {
441+ function instantAmend ( optionsParam : OptionsType < Temporal . Instant > ) {
449442 let options = optionsParam ;
450443 if ( ! hasTimeOptions ( options ) && ! hasDateOptions ( options ) ) {
451444 options = ObjectAssign ( { } , options , {
@@ -460,11 +453,11 @@ function instantAmend(optionsParam: InstantParams['toLocaleString'][1]) {
460453 return options ;
461454}
462455
463- function hasDateOptions ( options : Parameters < TypesWithToLocaleString [ 'toLocaleString' ] > [ 1 ] ) {
456+ function hasDateOptions ( options : OptionsType < TypesWithToLocaleString > ) {
464457 return 'year' in options || 'month' in options || 'day' in options || 'weekday' in options || 'dateStyle' in options ;
465458}
466459
467- function hasTimeOptions ( options : Parameters < TypesWithToLocaleString [ 'toLocaleString' ] > [ 1 ] ) {
460+ function hasTimeOptions ( options : OptionsType < TypesWithToLocaleString > ) {
468461 return (
469462 'hour' in options || 'minute' in options || 'second' in options || 'timeStyle' in options || 'dayPeriod' in options
470463 ) ;
@@ -509,7 +502,8 @@ type TypesWithToLocaleString =
509502 | Temporal . PlainTime
510503 | Temporal . PlainYearMonth
511504 | Temporal . PlainMonthDay
512- | Temporal . ZonedDateTime ;
505+ | Temporal . ZonedDateTime
506+ | Temporal . Instant ;
513507
514508function extractOverrides ( temporalObj : Params [ 'format' ] [ 0 ] , main : DateTimeFormatImpl ) {
515509 const DateTime = GetIntrinsic ( '%Temporal.PlainDateTime%' ) ;
0 commit comments