Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / Temporal / PlainDate / prototype / until / largestunit-higher-units.js
blob5962cf31bc80c5ebe7fcd75de116a7e6eff132f4
1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
2 // Copyright (C) 2021 Igalia, S.L. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
5 /*---
6 esid: sec-temporal.plaindate.prototype.until
7 description: Tests calculations with higher largestUnit than the default of 'days'
8 includes: [compareArray.js, temporalHelpers.js]
9 features: [Temporal]
10 ---*/
12 const date = new Temporal.PlainDate(1969, 7, 24);
13 const later = Temporal.PlainDate.from({ year: 2019, month: 7, day: 24 });
14 const duration = date.until(later, { largestUnit: "years" });
15 TemporalHelpers.assertDuration(duration, /* years = */ 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, "crossing epoch");
17 const feb20 = Temporal.PlainDate.from("2020-02-01");
18 const feb21 = Temporal.PlainDate.from("2021-02-01");
19 TemporalHelpers.assertDuration(feb20.until(feb21, { largestUnit: "years" }), /* years = */ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "start of February, years");
20 TemporalHelpers.assertDuration(feb20.until(feb21, { largestUnit: "months" }), 0, /* months = */ 12, 0, 0, 0, 0, 0, 0, 0, 0, "start of February, months");
21 TemporalHelpers.assertDuration(feb20.until(feb21, { largestUnit: "weeks" }), 0, 0, /* weeks = */ 52, /* days = */ 2, 0, 0, 0, 0, 0, 0, "start of February, weeks");
23 const lastFeb21 = new Temporal.PlainDate(2021, 2, 28);
24 const lastFeb22 = new Temporal.PlainDate(2022, 2, 28);
25 TemporalHelpers.assertDuration(lastFeb21.until(lastFeb22, { largestUnit: "years" }), /* years = */ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "end of February, years");
26 TemporalHelpers.assertDuration(lastFeb21.until(lastFeb22, { largestUnit: "months" }), 0, /* months = */ 12, 0, 0, 0, 0, 0, 0, 0, 0, "end of February, months");
27 TemporalHelpers.assertDuration(lastFeb21.until(lastFeb22, { largestUnit: "weeks" }), 0, 0, /* weeks = */ 52, /* days = */ 1, 0, 0, 0, 0, 0, 0, "end of February, weeks");
29 reportCompare(0, 0);