@@ -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
+ function ParseTemporalDurationString ( 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 ] ) ) {
@@ -690,8 +690,19 @@ export function ParseTemporalDurationString(isoString) {
690
690
seconds += MathTrunc ( excessNanoseconds / 1e9 ) % 60 ;
691
691
minutes += MathTrunc ( excessNanoseconds / 60e9 ) ;
692
692
693
- RejectDuration ( years , months , weeks , days , hours , minutes , seconds , milliseconds , microseconds , nanoseconds ) ;
694
- return { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } ;
693
+ const TemporalDuration = GetIntrinsic ( '%Temporal.Duration%' ) ;
694
+ return new TemporalDuration (
695
+ years ,
696
+ months ,
697
+ weeks ,
698
+ days ,
699
+ hours ,
700
+ minutes ,
701
+ seconds ,
702
+ milliseconds ,
703
+ microseconds ,
704
+ nanoseconds
705
+ ) ;
695
706
}
696
707
697
708
export function RegulateISODate ( year , month , day , overflow ) {
@@ -738,49 +749,6 @@ export function RegulateISOYearMonth(year, month, overflow) {
738
749
return { year, month } ;
739
750
}
740
751
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
752
export function ToTemporalPartialDurationRecord ( temporalDurationLike ) {
785
753
if ( Type ( temporalDurationLike ) !== 'Object' ) {
786
754
throw new TypeErrorCtor ( 'invalid duration-like' ) ;
@@ -1312,20 +1280,41 @@ export function ToTemporalDateTime(item, options = undefined) {
1312
1280
1313
1281
export function ToTemporalDuration ( item ) {
1314
1282
if ( IsTemporalDuration ( item ) ) return item ;
1315
- let { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } =
1316
- ToTemporalDurationRecord ( item ) ;
1283
+ if ( Type ( item ) !== 'Object' ) {
1284
+ return ParseTemporalDurationString ( RequireString ( item ) ) ;
1285
+ }
1286
+ const result = {
1287
+ years : 0 ,
1288
+ months : 0 ,
1289
+ weeks : 0 ,
1290
+ days : 0 ,
1291
+ hours : 0 ,
1292
+ minutes : 0 ,
1293
+ seconds : 0 ,
1294
+ milliseconds : 0 ,
1295
+ microseconds : 0 ,
1296
+ nanoseconds : 0
1297
+ } ;
1298
+ let partial = ToTemporalPartialDurationRecord ( item ) ;
1299
+ for ( let index = 0 ; index < DURATION_FIELDS . length ; index ++ ) {
1300
+ const property = DURATION_FIELDS [ index ] ;
1301
+ const value = partial [ property ] ;
1302
+ if ( value !== undefined ) {
1303
+ result [ property ] = value ;
1304
+ }
1305
+ }
1317
1306
const TemporalDuration = GetIntrinsic ( '%Temporal.Duration%' ) ;
1318
1307
return new TemporalDuration (
1319
- years ,
1320
- months ,
1321
- weeks ,
1322
- days ,
1323
- hours ,
1324
- minutes ,
1325
- seconds ,
1326
- milliseconds ,
1327
- microseconds ,
1328
- nanoseconds
1308
+ result . years ,
1309
+ result . months ,
1310
+ result . weeks ,
1311
+ result . days ,
1312
+ result . hours ,
1313
+ result . minutes ,
1314
+ result . seconds ,
1315
+ result . milliseconds ,
1316
+ result . microseconds ,
1317
+ result . nanoseconds
1329
1318
) ;
1330
1319
}
1331
1320
0 commit comments