Skip to content

Commit 6bcd95b

Browse files
ptomato12wrigja
authored andcommitted
Change relativeTo PlainDateTime to PlainDate in tests
We didn't update the tests when making this change. They were not broken, this all still worked, but in preparation for converting them to test262 let's simplify this. UPSTREAM_COMMIT=6b79fac239ab26ede017f40c8d75128759199e71
1 parent ec2b054 commit 6bcd95b

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

test/duration.mjs

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ describe('Duration', () => {
224224
throws(() => dy.add(d), RangeError);
225225
throws(() => dm.add(d), RangeError);
226226
throws(() => dw.add(d), RangeError);
227-
const relativeTo = Temporal.PlainDateTime.from('2000-01-01');
227+
const relativeTo = Temporal.PlainDate.from('2000-01-01');
228228
equal(`${d.add(dy, { relativeTo })}`, 'P1YT1H');
229229
equal(`${d.add(dm, { relativeTo })}`, 'P1MT1H');
230230
equal(`${d.add(dw, { relativeTo })}`, 'P1WT1H');
@@ -249,26 +249,26 @@ describe('Duration', () => {
249249
it('relativeTo affects year length', () => {
250250
const oneYear = new Duration(1);
251251
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');
254254
});
255255
it('relativeTo affects month length', () => {
256256
const oneMonth = new Duration(0, 1);
257257
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');
261261
});
262262
it('first this is resolved against relativeTo, then the argument against relativeTo + this', () => {
263263
const d1 = new Duration(0, 1, 0, 1);
264264
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);
266266
equal(`${d1.add(d2, { relativeTo })}`, 'P2M2D');
267267
});
268268
const oneDay = new Duration(0, 0, 0, 1);
269269
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');
272272
equal(`${oneDay.add(hours24, { relativeTo })}`, 'P2D');
273273
});
274274
it('relativeTo does not affect days if ZonedDateTime, and duration encompasses no DST change', () => {
@@ -349,8 +349,8 @@ describe('Duration', () => {
349349
'P1DT24H'
350350
);
351351
});
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');
354354
equal(`${oneDay.add(hours24, { relativeTo: { year: 2019, month: 11, day: 2 } })}`, 'P2D');
355355
});
356356
it('throws on wrong offset for ZonedDateTime relativeTo string', () => {
@@ -457,7 +457,7 @@ describe('Duration', () => {
457457
throws(() => dy.subtract(d), RangeError);
458458
throws(() => dm.subtract(d), RangeError);
459459
throws(() => dw.subtract(d), RangeError);
460-
const relativeTo = Temporal.PlainDateTime.from('2000-01-01');
460+
const relativeTo = Temporal.PlainDate.from('2000-01-01');
461461
equal(`${d.subtract(dy, { relativeTo })}`, '-P1Y');
462462
equal(`${d.subtract(dm, { relativeTo })}`, '-P1M');
463463
equal(`${d.subtract(dw, { relativeTo })}`, '-P1W');
@@ -482,26 +482,26 @@ describe('Duration', () => {
482482
it('relativeTo affects year length', () => {
483483
const oneYear = new Duration(1);
484484
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');
487487
});
488488
it('relativeTo affects month length', () => {
489489
const oneMonth = new Duration(0, 1);
490490
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');
494494
});
495495
it('first this is resolved against relativeTo, then the argument against relativeTo + this', () => {
496496
const d1 = new Duration(0, 2, 1, 4);
497497
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);
499499
equal(`${d1.subtract(d2, { relativeTo })}`, 'P1M3D');
500500
});
501501
const oneDay = new Duration(0, 0, 0, 1);
502502
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');
505505
equal(`${oneDay.subtract(hours24, { relativeTo })}`, 'PT0S');
506506
});
507507
it('relativeTo does not affect days if ZonedDateTime, and duration encompasses no DST change', () => {
@@ -556,8 +556,8 @@ describe('Duration', () => {
556556
'PT1H'
557557
);
558558
});
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');
561561
equal(`${oneDay.subtract(hours24, { relativeTo: { year: 2019, month: 11, day: 2 } })}`, 'PT0S');
562562
});
563563
it('throws on wrong offset for ZonedDateTime relativeTo string', () => {
@@ -679,7 +679,7 @@ describe('Duration', () => {
679679
describe('Duration.round()', () => {
680680
const d = new Duration(5, 5, 5, 5, 5, 5, 5, 5, 5, 5);
681681
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');
683683
it('parameter may only be an object or string', () => {
684684
[null, 1, true, Symbol('foo'), 1n].forEach((badOptions) => throws(() => d.round(badOptions), TypeError));
685685
});
@@ -760,8 +760,8 @@ describe('Duration', () => {
760760
it('days are 24 hours if relativeTo not given', () => {
761761
equal(`${hours25.round({ largestUnit: 'days' })}`, 'P1DT1H');
762762
});
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');
765765
equal(`${hours25.round({ largestUnit: 'days', relativeTo })}`, 'P1DT1H');
766766
});
767767
it('days are 24 hours if relativeTo is ZonedDateTime, and duration encompasses no DST change', () => {
@@ -846,8 +846,8 @@ describe('Duration', () => {
846846
'P1D'
847847
);
848848
});
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');
851851
equal(`${hours25.round({ largestUnit: 'days', relativeTo: { year: 2019, month: 11, day: 2 } })}`, 'P1DT1H');
852852
});
853853
it('accepts datetime string equivalents or fields for relativeTo', () => {
@@ -1224,7 +1224,7 @@ describe('Duration', () => {
12241224
describe('Duration.total()', () => {
12251225
const d = new Duration(5, 5, 5, 5, 5, 5, 5, 5, 5, 5);
12261226
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');
12281228
it('parameter may only be an object or string', () => {
12291229
[null, 1, true, Symbol('foo'), 1n].forEach((badOptions) => throws(() => d.total(badOptions), TypeError));
12301230
});
@@ -1377,7 +1377,7 @@ describe('Duration', () => {
13771377
equal(negativeD2.total({ unit: 'nanoseconds' }), -totalD2.nanoseconds);
13781378
});
13791379

1380-
const endpoint = relativeTo.add(d);
1380+
const endpoint = relativeTo.toPlainDateTime().add(d);
13811381
const options = (unit) => ({ largestUnit: unit, smallestUnit: unit, roundingMode: 'trunc' });
13821382
const fullYears = 5;
13831383
const fullDays = endpoint.since(relativeTo, options('days')).days;
@@ -1435,8 +1435,8 @@ describe('Duration', () => {
14351435
);
14361436
});
14371437
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');
14401440
equal(oneDay.total({ unit: 'hours', relativeTo }), 24);
14411441
});
14421442
it('relativeTo does not affect days if ZonedDateTime, and duration encompasses no DST change', () => {
@@ -1586,7 +1586,7 @@ describe('Duration', () => {
15861586
describe('date units', () => {
15871587
const d1 = new Duration(5, 5, 5, 5, 5, 5, 5, 5, 5, 5);
15881588
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');
15901590
it('relativeTo is required', () => throws(() => Duration.compare(d1, d2)), RangeError);
15911591
it('equal', () => equal(Duration.compare(d1, d1, { relativeTo }), 0));
15921592
it('smaller/larger', () => equal(Duration.compare(d2, d1, { relativeTo }), -1));
@@ -1617,23 +1617,23 @@ describe('Duration', () => {
16171617
it('relativeTo affects year length', () => {
16181618
const oneYear = new Duration(1);
16191619
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);
16221622
});
16231623
it('relativeTo affects month length', () => {
16241624
const oneMonth = new Duration(0, 1);
16251625
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);
16291629
});
16301630
const oneDay = new Duration(0, 0, 0, 1);
16311631
const hours24 = new Duration(0, 0, 0, 0, 24);
16321632
it('relativeTo not required for days', () => {
16331633
equal(Duration.compare(oneDay, hours24), 0);
16341634
});
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');
16371637
equal(Duration.compare(oneDay, hours24, { relativeTo }), 0);
16381638
});
16391639
it('relativeTo does not affect days if ZonedDateTime, and duration encompasses no DST change', () => {
@@ -1653,8 +1653,8 @@ describe('Duration', () => {
16531653
1
16541654
);
16551655
});
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);
16581658
equal(Duration.compare(oneDay, hours24, { relativeTo: { year: 2019, month: 11, day: 3 } }), 0);
16591659
});
16601660
it('at least the required properties must be present in relativeTo', () => {

0 commit comments

Comments
 (0)