@@ -641,7 +641,7 @@ export function ParseTemporalTimeZoneString(stringIdent) {
641
641
throw new ErrorCtor ( 'this line should not be reached' ) ;
642
642
}
643
643
644
- export function ParseTemporalDurationString ( isoString ) {
644
+ export function ParseTemporalDurationStringRaw ( isoString ) {
645
645
const match = Call ( RegExpPrototypeExec , PARSE . duration , [ isoString ] ) ;
646
646
if ( ! match ) throw new RangeErrorCtor ( `invalid duration: ${ isoString } ` ) ;
647
647
if ( Call ( ArrayPrototypeEvery , match , [ ( part , i ) => i < 2 || part === undefined ] ) ) {
@@ -694,6 +694,24 @@ export function ParseTemporalDurationString(isoString) {
694
694
return { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } ;
695
695
}
696
696
697
+ function ParseTemporalDurationString ( isoString ) {
698
+ const { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } =
699
+ ParseTemporalDurationStringRaw ( isoString ) ;
700
+ const TemporalDuration = GetIntrinsic ( '%Temporal.Duration%' ) ;
701
+ return new TemporalDuration (
702
+ years ,
703
+ months ,
704
+ weeks ,
705
+ days ,
706
+ hours ,
707
+ minutes ,
708
+ seconds ,
709
+ milliseconds ,
710
+ microseconds ,
711
+ nanoseconds
712
+ ) ;
713
+ }
714
+
697
715
export function RegulateISODate ( year , month , day , overflow ) {
698
716
switch ( overflow ) {
699
717
case 'reject' :
@@ -738,49 +756,6 @@ export function RegulateISOYearMonth(year, month, overflow) {
738
756
return { year, month } ;
739
757
}
740
758
741
- export function ToTemporalDurationRecord ( item ) {
742
- if ( Type ( item ) !== 'Object' ) {
743
- return ParseTemporalDurationString ( RequireString ( item ) ) ;
744
- }
745
- if ( IsTemporalDuration ( item ) ) {
746
- return {
747
- years : GetSlot ( item , YEARS ) ,
748
- months : GetSlot ( item , MONTHS ) ,
749
- weeks : GetSlot ( item , WEEKS ) ,
750
- days : GetSlot ( item , DAYS ) ,
751
- hours : GetSlot ( item , HOURS ) ,
752
- minutes : GetSlot ( item , MINUTES ) ,
753
- seconds : GetSlot ( item , SECONDS ) ,
754
- milliseconds : GetSlot ( item , MILLISECONDS ) ,
755
- microseconds : GetSlot ( item , MICROSECONDS ) ,
756
- nanoseconds : GetSlot ( item , NANOSECONDS )
757
- } ;
758
- }
759
- const result = {
760
- years : 0 ,
761
- months : 0 ,
762
- weeks : 0 ,
763
- days : 0 ,
764
- hours : 0 ,
765
- minutes : 0 ,
766
- seconds : 0 ,
767
- milliseconds : 0 ,
768
- microseconds : 0 ,
769
- nanoseconds : 0
770
- } ;
771
- let partial = ToTemporalPartialDurationRecord ( item ) ;
772
- for ( let index = 0 ; index < DURATION_FIELDS . length ; index ++ ) {
773
- const property = DURATION_FIELDS [ index ] ;
774
- const value = partial [ property ] ;
775
- if ( value !== undefined ) {
776
- result [ property ] = value ;
777
- }
778
- }
779
- let { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } = result ;
780
- RejectDuration ( years , months , weeks , days , hours , minutes , seconds , milliseconds , microseconds , nanoseconds ) ;
781
- return result ;
782
- }
783
-
784
759
export function ToTemporalPartialDurationRecord ( temporalDurationLike ) {
785
760
if ( Type ( temporalDurationLike ) !== 'Object' ) {
786
761
throw new TypeErrorCtor ( 'invalid duration-like' ) ;
@@ -1312,20 +1287,41 @@ export function ToTemporalDateTime(item, options = undefined) {
1312
1287
1313
1288
export function ToTemporalDuration ( item ) {
1314
1289
if ( IsTemporalDuration ( item ) ) return item ;
1315
- let { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } =
1316
- ToTemporalDurationRecord ( item ) ;
1290
+ if ( Type ( item ) !== 'Object' ) {
1291
+ return ParseTemporalDurationString ( RequireString ( item ) ) ;
1292
+ }
1293
+ const result = {
1294
+ years : 0 ,
1295
+ months : 0 ,
1296
+ weeks : 0 ,
1297
+ days : 0 ,
1298
+ hours : 0 ,
1299
+ minutes : 0 ,
1300
+ seconds : 0 ,
1301
+ milliseconds : 0 ,
1302
+ microseconds : 0 ,
1303
+ nanoseconds : 0
1304
+ } ;
1305
+ let partial = ToTemporalPartialDurationRecord ( item ) ;
1306
+ for ( let index = 0 ; index < DURATION_FIELDS . length ; index ++ ) {
1307
+ const property = DURATION_FIELDS [ index ] ;
1308
+ const value = partial [ property ] ;
1309
+ if ( value !== undefined ) {
1310
+ result [ property ] = value ;
1311
+ }
1312
+ }
1317
1313
const TemporalDuration = GetIntrinsic ( '%Temporal.Duration%' ) ;
1318
1314
return new TemporalDuration (
1319
- years ,
1320
- months ,
1321
- weeks ,
1322
- days ,
1323
- hours ,
1324
- minutes ,
1325
- seconds ,
1326
- milliseconds ,
1327
- microseconds ,
1328
- nanoseconds
1315
+ result . years ,
1316
+ result . months ,
1317
+ result . weeks ,
1318
+ result . days ,
1319
+ result . hours ,
1320
+ result . minutes ,
1321
+ result . seconds ,
1322
+ result . milliseconds ,
1323
+ result . microseconds ,
1324
+ result . nanoseconds
1329
1325
) ;
1330
1326
}
1331
1327
0 commit comments