@@ -1235,97 +1235,6 @@ describe('Duration', () => {
1235
1235
} ) ;
1236
1236
} ) ;
1237
1237
describe ( 'Duration.compare' , ( ) => {
1238
- describe ( 'time units only' , ( ) => {
1239
- const d1 = new Duration ( 0 , 0 , 0 , 0 , 5 , 5 , 5 , 5 , 5 , 5 ) ;
1240
- const d2 = new Duration ( 0 , 0 , 0 , 0 , 5 , 4 , 5 , 5 , 5 , 5 ) ;
1241
- it ( 'equal' , ( ) => equal ( Duration . compare ( d1 , d1 ) , 0 ) ) ;
1242
- it ( 'smaller/larger' , ( ) => equal ( Duration . compare ( d2 , d1 ) , - 1 ) ) ;
1243
- it ( 'larger/smaller' , ( ) => equal ( Duration . compare ( d1 , d2 ) , 1 ) ) ;
1244
- it ( 'negative/negative equal' , ( ) => equal ( Duration . compare ( d1 . negated ( ) , d1 . negated ( ) ) , 0 ) ) ;
1245
- it ( 'negative/negative smaller/larger' , ( ) => equal ( Duration . compare ( d2 . negated ( ) , d1 . negated ( ) ) , 1 ) ) ;
1246
- it ( 'negative/negative larger/smaller' , ( ) => equal ( Duration . compare ( d1 . negated ( ) , d2 . negated ( ) ) , - 1 ) ) ;
1247
- it ( 'negative/positive' , ( ) => equal ( Duration . compare ( d1 . negated ( ) , d2 ) , - 1 ) ) ;
1248
- it ( 'positive/negative' , ( ) => equal ( Duration . compare ( d1 , d2 . negated ( ) ) , 1 ) ) ;
1249
- } ) ;
1250
- describe ( 'date units' , ( ) => {
1251
- const d1 = new Duration ( 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 ) ;
1252
- const d2 = new Duration ( 5 , 5 , 5 , 5 , 5 , 4 , 5 , 5 , 5 , 5 ) ;
1253
- const relativeTo = Temporal . PlainDate . from ( '2017-01-01' ) ;
1254
- it ( 'relativeTo is required' , ( ) => throws ( ( ) => Duration . compare ( d1 , d2 ) ) , RangeError ) ;
1255
- it ( 'equal' , ( ) => equal ( Duration . compare ( d1 , d1 , { relativeTo } ) , 0 ) ) ;
1256
- it ( 'smaller/larger' , ( ) => equal ( Duration . compare ( d2 , d1 , { relativeTo } ) , - 1 ) ) ;
1257
- it ( 'larger/smaller' , ( ) => equal ( Duration . compare ( d1 , d2 , { relativeTo } ) , 1 ) ) ;
1258
- it ( 'negative/negative equal' , ( ) => equal ( Duration . compare ( d1 . negated ( ) , d1 . negated ( ) , { relativeTo } ) , 0 ) ) ;
1259
- it ( 'negative/negative smaller/larger' , ( ) =>
1260
- equal ( Duration . compare ( d2 . negated ( ) , d1 . negated ( ) , { relativeTo } ) , 1 ) ) ;
1261
- it ( 'negative/negative larger/smaller' , ( ) =>
1262
- equal ( Duration . compare ( d1 . negated ( ) , d2 . negated ( ) , { relativeTo } ) , - 1 ) ) ;
1263
- it ( 'negative/positive' , ( ) => equal ( Duration . compare ( d1 . negated ( ) , d2 , { relativeTo } ) , - 1 ) ) ;
1264
- it ( 'positive/negative' , ( ) => equal ( Duration . compare ( d1 , d2 . negated ( ) , { relativeTo } ) , 1 ) ) ;
1265
- } ) ;
1266
- it ( 'casts first argument' , ( ) => {
1267
- equal ( Duration . compare ( { hours : 12 } , new Duration ( ) ) , 1 ) ;
1268
- equal ( Duration . compare ( 'PT12H' , new Duration ( ) ) , 1 ) ;
1269
- } ) ;
1270
- it ( 'casts second argument' , ( ) => {
1271
- equal ( Duration . compare ( new Duration ( ) , { hours : 12 } ) , - 1 ) ;
1272
- equal ( Duration . compare ( new Duration ( ) , 'PT12H' ) , - 1 ) ;
1273
- } ) ;
1274
- it ( 'object must contain at least one correctly-spelled property' , ( ) => {
1275
- throws ( ( ) => Duration . compare ( { hour : 12 } , new Duration ( ) ) , TypeError ) ;
1276
- throws ( ( ) => Duration . compare ( new Duration ( ) , { hour : 12 } ) , TypeError ) ;
1277
- } ) ;
1278
- it ( 'ignores incorrect properties' , ( ) => {
1279
- equal ( Duration . compare ( { hours : 12 , minute : 5 } , { hours : 12 , day : 5 } ) , 0 ) ;
1280
- } ) ;
1281
- it ( 'relativeTo affects year length' , ( ) => {
1282
- const oneYear = new Duration ( 1 ) ;
1283
- const days365 = new Duration ( 0 , 0 , 0 , 365 ) ;
1284
- equal ( Duration . compare ( oneYear , days365 , { relativeTo : Temporal . PlainDate . from ( '2017-01-01' ) } ) , 0 ) ;
1285
- equal ( Duration . compare ( oneYear , days365 , { relativeTo : Temporal . PlainDate . from ( '2016-01-01' ) } ) , 1 ) ;
1286
- } ) ;
1287
- it ( 'relativeTo affects month length' , ( ) => {
1288
- const oneMonth = new Duration ( 0 , 1 ) ;
1289
- const days30 = new Duration ( 0 , 0 , 0 , 30 ) ;
1290
- equal ( Duration . compare ( oneMonth , days30 , { relativeTo : Temporal . PlainDate . from ( '2018-04-01' ) } ) , 0 ) ;
1291
- equal ( Duration . compare ( oneMonth , days30 , { relativeTo : Temporal . PlainDate . from ( '2018-03-01' ) } ) , 1 ) ;
1292
- equal ( Duration . compare ( oneMonth , days30 , { relativeTo : Temporal . PlainDate . from ( '2018-02-01' ) } ) , - 1 ) ;
1293
- } ) ;
1294
- const oneDay = new Duration ( 0 , 0 , 0 , 1 ) ;
1295
- const hours24 = new Duration ( 0 , 0 , 0 , 0 , 24 ) ;
1296
- it ( 'relativeTo not required for days' , ( ) => {
1297
- equal ( Duration . compare ( oneDay , hours24 ) , 0 ) ;
1298
- } ) ;
1299
- it ( 'relativeTo does not affect days if PlainDate' , ( ) => {
1300
- const relativeTo = Temporal . PlainDate . from ( '2017-01-01' ) ;
1301
- equal ( Duration . compare ( oneDay , hours24 , { relativeTo } ) , 0 ) ;
1302
- } ) ;
1303
- it ( 'relativeTo does not affect days if ZonedDateTime, and duration encompasses no DST change' , ( ) => {
1304
- const relativeTo = Temporal . ZonedDateTime . from ( '2017-01-01T00:00[America/Montevideo]' ) ;
1305
- equal ( Duration . compare ( oneDay , hours24 , { relativeTo } ) , 0 ) ;
1306
- } ) ;
1307
- it ( 'relativeTo does affect days if ZonedDateTime, and duration encompasses DST change' , ( ) => {
1308
- const relativeTo = Temporal . ZonedDateTime . from ( '2019-11-03T00:00[America/Vancouver]' ) ;
1309
- equal ( Duration . compare ( oneDay , hours24 , { relativeTo } ) , 1 ) ;
1310
- } ) ;
1311
- it ( 'casts relativeTo to ZonedDateTime if possible' , ( ) => {
1312
- equal ( Duration . compare ( oneDay , hours24 , { relativeTo : '2019-11-03T00:00[America/Vancouver]' } ) , 1 ) ;
1313
- equal (
1314
- Duration . compare ( oneDay , hours24 , {
1315
- relativeTo : { year : 2019 , month : 11 , day : 3 , timeZone : 'America/Vancouver' }
1316
- } ) ,
1317
- 1
1318
- ) ;
1319
- } ) ;
1320
- it ( 'casts relativeTo to PlainDate if possible' , ( ) => {
1321
- equal ( Duration . compare ( oneDay , hours24 , { relativeTo : '2019-11-03' } ) , 0 ) ;
1322
- equal ( Duration . compare ( oneDay , hours24 , { relativeTo : { year : 2019 , month : 11 , day : 3 } } ) , 0 ) ;
1323
- } ) ;
1324
- it ( 'at least the required properties must be present in relativeTo' , ( ) => {
1325
- throws ( ( ) => Duration . compare ( oneDay , hours24 , { relativeTo : { month : 11 , day : 3 } } ) , TypeError ) ;
1326
- throws ( ( ) => Duration . compare ( oneDay , hours24 , { relativeTo : { year : 2019 , month : 11 } } ) , TypeError ) ;
1327
- throws ( ( ) => Duration . compare ( oneDay , hours24 , { relativeTo : { year : 2019 , day : 3 } } ) , TypeError ) ;
1328
- } ) ;
1329
1238
it ( 'does not lose precision when totaling everything down to nanoseconds' , ( ) => {
1330
1239
notEqual ( Duration . compare ( { days : 200 } , { days : 200 , nanoseconds : 1 } ) , 0 ) ;
1331
1240
} ) ;
0 commit comments