@@ -224,7 +224,7 @@ describe('Duration', () => {
224
224
throws ( ( ) => dy . add ( d ) , RangeError ) ;
225
225
throws ( ( ) => dm . add ( d ) , RangeError ) ;
226
226
throws ( ( ) => dw . add ( d ) , RangeError ) ;
227
- const relativeTo = Temporal . PlainDateTime . from ( '2000-01-01' ) ;
227
+ const relativeTo = Temporal . PlainDate . from ( '2000-01-01' ) ;
228
228
equal ( `${ d . add ( dy , { relativeTo } ) } ` , 'P1YT1H' ) ;
229
229
equal ( `${ d . add ( dm , { relativeTo } ) } ` , 'P1MT1H' ) ;
230
230
equal ( `${ d . add ( dw , { relativeTo } ) } ` , 'P1WT1H' ) ;
@@ -249,26 +249,26 @@ describe('Duration', () => {
249
249
it ( 'relativeTo affects year length' , ( ) => {
250
250
const oneYear = new Duration ( 1 ) ;
251
251
const days365 = new Duration ( 0 , 0 , 0 , 365 ) ;
252
- equal ( `${ oneYear . add ( days365 , { relativeTo : Temporal . PlainDateTime . from ( '2016-01-01' ) } ) } ` , 'P2Y' ) ;
253
- equal ( `${ oneYear . add ( days365 , { relativeTo : Temporal . PlainDateTime . from ( '2015-01-01' ) } ) } ` , 'P1Y11M30D' ) ;
252
+ equal ( `${ oneYear . add ( days365 , { relativeTo : Temporal . PlainDate . from ( '2016-01-01' ) } ) } ` , 'P2Y' ) ;
253
+ equal ( `${ oneYear . add ( days365 , { relativeTo : Temporal . PlainDate . from ( '2015-01-01' ) } ) } ` , 'P1Y11M30D' ) ;
254
254
} ) ;
255
255
it ( 'relativeTo affects month length' , ( ) => {
256
256
const oneMonth = new Duration ( 0 , 1 ) ;
257
257
const days30 = new Duration ( 0 , 0 , 0 , 30 ) ;
258
- equal ( `${ oneMonth . add ( days30 , { relativeTo : Temporal . PlainDateTime . from ( '2018-01-01' ) } ) } ` , 'P2M2D' ) ;
259
- equal ( `${ oneMonth . add ( days30 , { relativeTo : Temporal . PlainDateTime . from ( '2018-02-01' ) } ) } ` , 'P1M30D' ) ;
260
- equal ( `${ oneMonth . add ( days30 , { relativeTo : Temporal . PlainDateTime . from ( '2018-03-01' ) } ) } ` , 'P2M' ) ;
258
+ equal ( `${ oneMonth . add ( days30 , { relativeTo : Temporal . PlainDate . from ( '2018-01-01' ) } ) } ` , 'P2M2D' ) ;
259
+ equal ( `${ oneMonth . add ( days30 , { relativeTo : Temporal . PlainDate . from ( '2018-02-01' ) } ) } ` , 'P1M30D' ) ;
260
+ equal ( `${ oneMonth . add ( days30 , { relativeTo : Temporal . PlainDate . from ( '2018-03-01' ) } ) } ` , 'P2M' ) ;
261
261
} ) ;
262
262
it ( 'first this is resolved against relativeTo, then the argument against relativeTo + this' , ( ) => {
263
263
const d1 = new Duration ( 0 , 1 , 0 , 1 ) ;
264
264
const d2 = new Duration ( 0 , 1 , 0 , 1 ) ;
265
- const relativeTo = new Temporal . PlainDateTime ( 2000 , 1 , 1 ) ;
265
+ const relativeTo = new Temporal . PlainDate ( 2000 , 1 , 1 ) ;
266
266
equal ( `${ d1 . add ( d2 , { relativeTo } ) } ` , 'P2M2D' ) ;
267
267
} ) ;
268
268
const oneDay = new Duration ( 0 , 0 , 0 , 1 ) ;
269
269
const hours24 = new Duration ( 0 , 0 , 0 , 0 , 24 ) ;
270
- it ( 'relativeTo does not affect days if PlainDateTime ' , ( ) => {
271
- const relativeTo = Temporal . PlainDateTime . from ( '2017-01-01' ) ;
270
+ it ( 'relativeTo does not affect days if PlainDate ' , ( ) => {
271
+ const relativeTo = Temporal . PlainDate . from ( '2017-01-01' ) ;
272
272
equal ( `${ oneDay . add ( hours24 , { relativeTo } ) } ` , 'P2D' ) ;
273
273
} ) ;
274
274
it ( 'relativeTo does not affect days if ZonedDateTime, and duration encompasses no DST change' , ( ) => {
@@ -349,8 +349,8 @@ describe('Duration', () => {
349
349
'P1DT24H'
350
350
) ;
351
351
} ) ;
352
- it ( 'casts relativeTo to PlainDateTime if possible' , ( ) => {
353
- equal ( `${ oneDay . add ( hours24 , { relativeTo : '2019-11-02T00:00 ' } ) } ` , 'P2D' ) ;
352
+ it ( 'casts relativeTo to PlainDate if possible' , ( ) => {
353
+ equal ( `${ oneDay . add ( hours24 , { relativeTo : '2019-11-02 ' } ) } ` , 'P2D' ) ;
354
354
equal ( `${ oneDay . add ( hours24 , { relativeTo : { year : 2019 , month : 11 , day : 2 } } ) } ` , 'P2D' ) ;
355
355
} ) ;
356
356
it ( 'throws on wrong offset for ZonedDateTime relativeTo string' , ( ) => {
@@ -457,7 +457,7 @@ describe('Duration', () => {
457
457
throws ( ( ) => dy . subtract ( d ) , RangeError ) ;
458
458
throws ( ( ) => dm . subtract ( d ) , RangeError ) ;
459
459
throws ( ( ) => dw . subtract ( d ) , RangeError ) ;
460
- const relativeTo = Temporal . PlainDateTime . from ( '2000-01-01' ) ;
460
+ const relativeTo = Temporal . PlainDate . from ( '2000-01-01' ) ;
461
461
equal ( `${ d . subtract ( dy , { relativeTo } ) } ` , '-P1Y' ) ;
462
462
equal ( `${ d . subtract ( dm , { relativeTo } ) } ` , '-P1M' ) ;
463
463
equal ( `${ d . subtract ( dw , { relativeTo } ) } ` , '-P1W' ) ;
@@ -482,26 +482,26 @@ describe('Duration', () => {
482
482
it ( 'relativeTo affects year length' , ( ) => {
483
483
const oneYear = new Duration ( 1 ) ;
484
484
const days365 = new Duration ( 0 , 0 , 0 , 365 ) ;
485
- equal ( `${ oneYear . subtract ( days365 , { relativeTo : Temporal . PlainDateTime . from ( '2017-01-01' ) } ) } ` , 'PT0S' ) ;
486
- equal ( `${ oneYear . subtract ( days365 , { relativeTo : Temporal . PlainDateTime . from ( '2016-01-01' ) } ) } ` , 'P1D' ) ;
485
+ equal ( `${ oneYear . subtract ( days365 , { relativeTo : Temporal . PlainDate . from ( '2017-01-01' ) } ) } ` , 'PT0S' ) ;
486
+ equal ( `${ oneYear . subtract ( days365 , { relativeTo : Temporal . PlainDate . from ( '2016-01-01' ) } ) } ` , 'P1D' ) ;
487
487
} ) ;
488
488
it ( 'relativeTo affects month length' , ( ) => {
489
489
const oneMonth = new Duration ( 0 , 1 ) ;
490
490
const days30 = new Duration ( 0 , 0 , 0 , 30 ) ;
491
- equal ( `${ oneMonth . subtract ( days30 , { relativeTo : Temporal . PlainDateTime . from ( '2018-02-01' ) } ) } ` , '-P2D' ) ;
492
- equal ( `${ oneMonth . subtract ( days30 , { relativeTo : Temporal . PlainDateTime . from ( '2018-03-01' ) } ) } ` , 'P1D' ) ;
493
- equal ( `${ oneMonth . subtract ( days30 , { relativeTo : Temporal . PlainDateTime . from ( '2018-04-01' ) } ) } ` , 'PT0S' ) ;
491
+ equal ( `${ oneMonth . subtract ( days30 , { relativeTo : Temporal . PlainDate . from ( '2018-02-01' ) } ) } ` , '-P2D' ) ;
492
+ equal ( `${ oneMonth . subtract ( days30 , { relativeTo : Temporal . PlainDate . from ( '2018-03-01' ) } ) } ` , 'P1D' ) ;
493
+ equal ( `${ oneMonth . subtract ( days30 , { relativeTo : Temporal . PlainDate . from ( '2018-04-01' ) } ) } ` , 'PT0S' ) ;
494
494
} ) ;
495
495
it ( 'first this is resolved against relativeTo, then the argument against relativeTo + this' , ( ) => {
496
496
const d1 = new Duration ( 0 , 2 , 1 , 4 ) ;
497
497
const d2 = new Duration ( 0 , 1 , 1 , 1 ) ;
498
- const relativeTo = new Temporal . PlainDateTime ( 2000 , 1 , 1 ) ;
498
+ const relativeTo = new Temporal . PlainDate ( 2000 , 1 , 1 ) ;
499
499
equal ( `${ d1 . subtract ( d2 , { relativeTo } ) } ` , 'P1M3D' ) ;
500
500
} ) ;
501
501
const oneDay = new Duration ( 0 , 0 , 0 , 1 ) ;
502
502
const hours24 = new Duration ( 0 , 0 , 0 , 0 , 24 ) ;
503
- it ( 'relativeTo does not affect days if PlainDateTime ' , ( ) => {
504
- const relativeTo = Temporal . PlainDateTime . from ( '2017-01-01' ) ;
503
+ it ( 'relativeTo does not affect days if PlainDate ' , ( ) => {
504
+ const relativeTo = Temporal . PlainDate . from ( '2017-01-01' ) ;
505
505
equal ( `${ oneDay . subtract ( hours24 , { relativeTo } ) } ` , 'PT0S' ) ;
506
506
} ) ;
507
507
it ( 'relativeTo does not affect days if ZonedDateTime, and duration encompasses no DST change' , ( ) => {
@@ -556,8 +556,8 @@ describe('Duration', () => {
556
556
'PT1H'
557
557
) ;
558
558
} ) ;
559
- it ( 'casts relativeTo to PlainDateTime if possible' , ( ) => {
560
- equal ( `${ oneDay . subtract ( hours24 , { relativeTo : '2019-11-02T00:00 ' } ) } ` , 'PT0S' ) ;
559
+ it ( 'casts relativeTo to PlainDate if possible' , ( ) => {
560
+ equal ( `${ oneDay . subtract ( hours24 , { relativeTo : '2019-11-02 ' } ) } ` , 'PT0S' ) ;
561
561
equal ( `${ oneDay . subtract ( hours24 , { relativeTo : { year : 2019 , month : 11 , day : 2 } } ) } ` , 'PT0S' ) ;
562
562
} ) ;
563
563
it ( 'throws on wrong offset for ZonedDateTime relativeTo string' , ( ) => {
@@ -679,7 +679,7 @@ describe('Duration', () => {
679
679
describe ( 'Duration.round()' , ( ) => {
680
680
const d = new Duration ( 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 ) ;
681
681
const d2 = new Duration ( 0 , 0 , 0 , 5 , 5 , 5 , 5 , 5 , 5 , 5 ) ;
682
- const relativeTo = Temporal . PlainDateTime . from ( '2020-01-01T00:00 ' ) ;
682
+ const relativeTo = Temporal . PlainDate . from ( '2020-01-01 ' ) ;
683
683
it ( 'parameter may only be an object or string' , ( ) => {
684
684
[ null , 1 , true , Symbol ( 'foo' ) , 1n ] . forEach ( ( badOptions ) => throws ( ( ) => d . round ( badOptions ) , TypeError ) ) ;
685
685
} ) ;
@@ -760,8 +760,8 @@ describe('Duration', () => {
760
760
it ( 'days are 24 hours if relativeTo not given' , ( ) => {
761
761
equal ( `${ hours25 . round ( { largestUnit : 'days' } ) } ` , 'P1DT1H' ) ;
762
762
} ) ;
763
- it ( 'days are 24 hours if relativeTo is PlainDateTime ' , ( ) => {
764
- const relativeTo = Temporal . PlainDateTime . from ( '2017-01-01' ) ;
763
+ it ( 'days are 24 hours if relativeTo is PlainDate ' , ( ) => {
764
+ const relativeTo = Temporal . PlainDate . from ( '2017-01-01' ) ;
765
765
equal ( `${ hours25 . round ( { largestUnit : 'days' , relativeTo } ) } ` , 'P1DT1H' ) ;
766
766
} ) ;
767
767
it ( 'days are 24 hours if relativeTo is ZonedDateTime, and duration encompasses no DST change' , ( ) => {
@@ -846,8 +846,8 @@ describe('Duration', () => {
846
846
'P1D'
847
847
) ;
848
848
} ) ;
849
- it ( 'casts relativeTo to PlainDateTime if possible' , ( ) => {
850
- equal ( `${ hours25 . round ( { largestUnit : 'days' , relativeTo : '2019-11-02T00:00 ' } ) } ` , 'P1DT1H' ) ;
849
+ it ( 'casts relativeTo to PlainDate if possible' , ( ) => {
850
+ equal ( `${ hours25 . round ( { largestUnit : 'days' , relativeTo : '2019-11-02 ' } ) } ` , 'P1DT1H' ) ;
851
851
equal ( `${ hours25 . round ( { largestUnit : 'days' , relativeTo : { year : 2019 , month : 11 , day : 2 } } ) } ` , 'P1DT1H' ) ;
852
852
} ) ;
853
853
it ( 'accepts datetime string equivalents or fields for relativeTo' , ( ) => {
@@ -1224,7 +1224,7 @@ describe('Duration', () => {
1224
1224
describe ( 'Duration.total()' , ( ) => {
1225
1225
const d = new Duration ( 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 ) ;
1226
1226
const d2 = new Duration ( 0 , 0 , 0 , 5 , 5 , 5 , 5 , 5 , 5 , 5 ) ;
1227
- const relativeTo = Temporal . PlainDateTime . from ( '2020-01-01T00:00 ' ) ;
1227
+ const relativeTo = Temporal . PlainDate . from ( '2020-01-01 ' ) ;
1228
1228
it ( 'parameter may only be an object or string' , ( ) => {
1229
1229
[ null , 1 , true , Symbol ( 'foo' ) , 1n ] . forEach ( ( badOptions ) => throws ( ( ) => d . total ( badOptions ) , TypeError ) ) ;
1230
1230
} ) ;
@@ -1377,7 +1377,7 @@ describe('Duration', () => {
1377
1377
equal ( negativeD2 . total ( { unit : 'nanoseconds' } ) , - totalD2 . nanoseconds ) ;
1378
1378
} ) ;
1379
1379
1380
- const endpoint = relativeTo . add ( d ) ;
1380
+ const endpoint = relativeTo . toPlainDateTime ( ) . add ( d ) ;
1381
1381
const options = ( unit ) => ( { largestUnit : unit , smallestUnit : unit , roundingMode : 'trunc' } ) ;
1382
1382
const fullYears = 5 ;
1383
1383
const fullDays = endpoint . since ( relativeTo , options ( 'days' ) ) . days ;
@@ -1435,8 +1435,8 @@ describe('Duration', () => {
1435
1435
) ;
1436
1436
} ) ;
1437
1437
const oneDay = new Duration ( 0 , 0 , 0 , 1 ) ;
1438
- it ( 'relativeTo does not affect days if PlainDateTime ' , ( ) => {
1439
- const relativeTo = Temporal . PlainDateTime . from ( '2017-01-01' ) ;
1438
+ it ( 'relativeTo does not affect days if PlainDate ' , ( ) => {
1439
+ const relativeTo = Temporal . PlainDate . from ( '2017-01-01' ) ;
1440
1440
equal ( oneDay . total ( { unit : 'hours' , relativeTo } ) , 24 ) ;
1441
1441
} ) ;
1442
1442
it ( 'relativeTo does not affect days if ZonedDateTime, and duration encompasses no DST change' , ( ) => {
@@ -1586,7 +1586,7 @@ describe('Duration', () => {
1586
1586
describe ( 'date units' , ( ) => {
1587
1587
const d1 = new Duration ( 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 ) ;
1588
1588
const d2 = new Duration ( 5 , 5 , 5 , 5 , 5 , 4 , 5 , 5 , 5 , 5 ) ;
1589
- const relativeTo = Temporal . PlainDateTime . from ( '2017-01-01' ) ;
1589
+ const relativeTo = Temporal . PlainDate . from ( '2017-01-01' ) ;
1590
1590
it ( 'relativeTo is required' , ( ) => throws ( ( ) => Duration . compare ( d1 , d2 ) ) , RangeError ) ;
1591
1591
it ( 'equal' , ( ) => equal ( Duration . compare ( d1 , d1 , { relativeTo } ) , 0 ) ) ;
1592
1592
it ( 'smaller/larger' , ( ) => equal ( Duration . compare ( d2 , d1 , { relativeTo } ) , - 1 ) ) ;
@@ -1617,23 +1617,23 @@ describe('Duration', () => {
1617
1617
it ( 'relativeTo affects year length' , ( ) => {
1618
1618
const oneYear = new Duration ( 1 ) ;
1619
1619
const days365 = new Duration ( 0 , 0 , 0 , 365 ) ;
1620
- equal ( Duration . compare ( oneYear , days365 , { relativeTo : Temporal . PlainDateTime . from ( '2017-01-01' ) } ) , 0 ) ;
1621
- equal ( Duration . compare ( oneYear , days365 , { relativeTo : Temporal . PlainDateTime . from ( '2016-01-01' ) } ) , 1 ) ;
1620
+ equal ( Duration . compare ( oneYear , days365 , { relativeTo : Temporal . PlainDate . from ( '2017-01-01' ) } ) , 0 ) ;
1621
+ equal ( Duration . compare ( oneYear , days365 , { relativeTo : Temporal . PlainDate . from ( '2016-01-01' ) } ) , 1 ) ;
1622
1622
} ) ;
1623
1623
it ( 'relativeTo affects month length' , ( ) => {
1624
1624
const oneMonth = new Duration ( 0 , 1 ) ;
1625
1625
const days30 = new Duration ( 0 , 0 , 0 , 30 ) ;
1626
- equal ( Duration . compare ( oneMonth , days30 , { relativeTo : Temporal . PlainDateTime . from ( '2018-04-01' ) } ) , 0 ) ;
1627
- equal ( Duration . compare ( oneMonth , days30 , { relativeTo : Temporal . PlainDateTime . from ( '2018-03-01' ) } ) , 1 ) ;
1628
- equal ( Duration . compare ( oneMonth , days30 , { relativeTo : Temporal . PlainDateTime . from ( '2018-02-01' ) } ) , - 1 ) ;
1626
+ equal ( Duration . compare ( oneMonth , days30 , { relativeTo : Temporal . PlainDate . from ( '2018-04-01' ) } ) , 0 ) ;
1627
+ equal ( Duration . compare ( oneMonth , days30 , { relativeTo : Temporal . PlainDate . from ( '2018-03-01' ) } ) , 1 ) ;
1628
+ equal ( Duration . compare ( oneMonth , days30 , { relativeTo : Temporal . PlainDate . from ( '2018-02-01' ) } ) , - 1 ) ;
1629
1629
} ) ;
1630
1630
const oneDay = new Duration ( 0 , 0 , 0 , 1 ) ;
1631
1631
const hours24 = new Duration ( 0 , 0 , 0 , 0 , 24 ) ;
1632
1632
it ( 'relativeTo not required for days' , ( ) => {
1633
1633
equal ( Duration . compare ( oneDay , hours24 ) , 0 ) ;
1634
1634
} ) ;
1635
- it ( 'relativeTo does not affect days if PlainDateTime ' , ( ) => {
1636
- const relativeTo = Temporal . PlainDateTime . from ( '2017-01-01' ) ;
1635
+ it ( 'relativeTo does not affect days if PlainDate ' , ( ) => {
1636
+ const relativeTo = Temporal . PlainDate . from ( '2017-01-01' ) ;
1637
1637
equal ( Duration . compare ( oneDay , hours24 , { relativeTo } ) , 0 ) ;
1638
1638
} ) ;
1639
1639
it ( 'relativeTo does not affect days if ZonedDateTime, and duration encompasses no DST change' , ( ) => {
@@ -1653,8 +1653,8 @@ describe('Duration', () => {
1653
1653
1
1654
1654
) ;
1655
1655
} ) ;
1656
- it ( 'casts relativeTo to PlainDateTime if possible' , ( ) => {
1657
- equal ( Duration . compare ( oneDay , hours24 , { relativeTo : '2019-11-03T00:00 ' } ) , 0 ) ;
1656
+ it ( 'casts relativeTo to PlainDate if possible' , ( ) => {
1657
+ equal ( Duration . compare ( oneDay , hours24 , { relativeTo : '2019-11-03 ' } ) , 0 ) ;
1658
1658
equal ( Duration . compare ( oneDay , hours24 , { relativeTo : { year : 2019 , month : 11 , day : 3 } } ) , 0 ) ;
1659
1659
} ) ;
1660
1660
it ( 'at least the required properties must be present in relativeTo' , ( ) => {
0 commit comments