Test PlainDate#{since,until}.

This commit is contained in:
Ms2ger 2022-01-20 11:54:12 +01:00 committed by Rick Waldron
parent a46aecc12a
commit 3dfc587f36
17 changed files with 548 additions and 0 deletions

View File

@ -0,0 +1,19 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaindate.prototype.since
description: since() should take length of month into account.
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const plainDate1 = Temporal.PlainDate.from("2019-01-01");
const plainDate2 = Temporal.PlainDate.from("2019-02-01");
const plainDate3 = Temporal.PlainDate.from("2019-03-01");
TemporalHelpers.assertDuration(plainDate2.since(plainDate1), 0, 0, 0, /* days = */ 31, 0, 0, 0, 0, 0, 0, "January 2019");
TemporalHelpers.assertDuration(plainDate3.since(plainDate2), 0, 0, 0, /* days = */ 28, 0, 0, 0, 0, 0, 0, "February 2019");
const plainDate4 = Temporal.PlainDate.from("2020-02-01");
const plainDate5 = Temporal.PlainDate.from("2020-03-01");
TemporalHelpers.assertDuration(plainDate5.since(plainDate4), 0, 0, 0, /* days = */ 29, 0, 0, 0, 0, 0, 0, "February 2020");

View File

@ -0,0 +1,21 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaindate.prototype.since
description: since() should take length of year into account.
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const plainDate1 = Temporal.PlainDate.from("2019-01-01");
const plainDate2 = Temporal.PlainDate.from("2020-01-01");
const plainDate3 = Temporal.PlainDate.from("2021-01-01");
TemporalHelpers.assertDuration(plainDate2.since(plainDate1), 0, 0, 0, /* days = */ 365, 0, 0, 0, 0, 0, 0, "From January 2019");
TemporalHelpers.assertDuration(plainDate3.since(plainDate2), 0, 0, 0, /* days = */ 366, 0, 0, 0, 0, 0, 0, "From January 2020");
const plainDate4 = Temporal.PlainDate.from("2019-06-01");
const plainDate5 = Temporal.PlainDate.from("2020-06-01");
const plainDate6 = Temporal.PlainDate.from("2021-06-01");
TemporalHelpers.assertDuration(plainDate5.since(plainDate4), 0, 0, 0, /* days = */ 366, 0, 0, 0, 0, 0, 0, "From June 2019");
TemporalHelpers.assertDuration(plainDate6.since(plainDate5), 0, 0, 0, /* days = */ 365, 0, 0, 0, 0, 0, 0, "From June 2020");

View File

@ -0,0 +1,34 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaindate.prototype.since
description: Should round relative to the receiver.
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const date1 = Temporal.PlainDate.from("2019-01-01");
const date2 = Temporal.PlainDate.from("2019-02-15");
TemporalHelpers.assertDuration(
date2.since(date1, { smallestUnit: "months", roundingMode: "halfExpand" }),
0, /* months = */ 1, 0, 0, 0, 0, 0, 0, 0, 0);
TemporalHelpers.assertDuration(
date1.since(date2, { smallestUnit: "months", roundingMode: "halfExpand" }),
0, /* months = */ -2, 0, 0, 0, 0, 0, 0, 0, 0);
const cases = [
["2019-03-01", "2019-01-29", 1, 3],
["2019-01-29", "2019-03-01", -1, -1],
["2019-03-29", "2019-01-30", 1, 29],
["2019-01-30", "2019-03-29", -1, -29],
["2019-03-30", "2019-01-31", 1, 28],
["2019-01-31", "2019-03-30", -1, -30],
["2019-03-31", "2019-01-31", 2, 0],
["2019-01-31", "2019-03-31", -2, 0]
];
for (const [end, start, months, days] of cases) {
const result = Temporal.PlainDate.from(end).since(start, { largestUnit: "months" });
TemporalHelpers.assertDuration(result, 0, months, 0, days, 0, 0, 0, 0, 0, 0, `${end} - ${start}`);
}

View File

@ -0,0 +1,28 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaindate.prototype.since
description: Tests calculations with roundingMode "trunc".
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const earlier = Temporal.PlainDate.from("2019-01-08");
const later = Temporal.PlainDate.from("2021-09-07");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "years", roundingIncrement: 4, roundingMode: "halfExpand" }),
/* years = */ 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "months", roundingIncrement: 10, roundingMode: "halfExpand" }),
0, /* months = */ 30, 0, 0, 0, 0, 0, 0, 0, 0, "months");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "weeks", roundingIncrement: 12, roundingMode: "halfExpand" }),
0, 0, /* weeks = */ 144, 0, 0, 0, 0, 0, 0, 0, "weeks");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "days", roundingIncrement: 100, roundingMode: "halfExpand" }),
0, 0, 0, /* days = */ 1000, 0, 0, 0, 0, 0, 0, "days");

View File

@ -0,0 +1,40 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaindate.prototype.since
description: Tests calculations with roundingMode "ceil".
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const earlier = Temporal.PlainDate.from("2019-01-08");
const later = Temporal.PlainDate.from("2021-09-07");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "years", roundingMode: "ceil" }),
/* years = */ 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "years", roundingMode: "ceil" }),
/* years = */ -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "months", roundingMode: "ceil" }),
0, /* months = */ 32, 0, 0, 0, 0, 0, 0, 0, 0, "months");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "months", roundingMode: "ceil" }),
0, /* months = */ -31, 0, 0, 0, 0, 0, 0, 0, 0, "months");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "weeks", roundingMode: "ceil" }),
0, 0, /* weeks = */ 139, 0, 0, 0, 0, 0, 0, 0, "weeks");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "weeks", roundingMode: "ceil" }),
0, 0, /* weeks = */ -139, 0, 0, 0, 0, 0, 0, 0, "weeks");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "days", roundingMode: "ceil" }),
0, 0, 0, /* days = */ 973, 0, 0, 0, 0, 0, 0, "days");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "days", roundingMode: "ceil" }),
0, 0, 0, /* days = */ -973, 0, 0, 0, 0, 0, 0, "days");

View File

@ -0,0 +1,40 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaindate.prototype.since
description: Tests calculations with roundingMode "floor".
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const earlier = Temporal.PlainDate.from("2019-01-08");
const later = Temporal.PlainDate.from("2021-09-07");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "years", roundingMode: "floor" }),
/* years = */ 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "years", roundingMode: "floor" }),
/* years = */ -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "months", roundingMode: "floor" }),
0, /* months = */ 31, 0, 0, 0, 0, 0, 0, 0, 0, "months");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "months", roundingMode: "floor" }),
0, /* months = */ -32, 0, 0, 0, 0, 0, 0, 0, 0, "months");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "weeks", roundingMode: "floor" }),
0, 0, /* weeks = */ 139, 0, 0, 0, 0, 0, 0, 0, "weeks");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "weeks", roundingMode: "floor" }),
0, 0, /* weeks = */ -139, 0, 0, 0, 0, 0, 0, 0, "weeks");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "days", roundingMode: "floor" }),
0, 0, 0, /* days = */ 973, 0, 0, 0, 0, 0, 0, "days");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "days", roundingMode: "floor" }),
0, 0, 0, /* days = */ -973, 0, 0, 0, 0, 0, 0, "days");

View File

@ -0,0 +1,40 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaindate.prototype.since
description: Tests calculations with roundingMode "halfExpand".
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const earlier = Temporal.PlainDate.from("2019-01-08");
const later = Temporal.PlainDate.from("2021-09-07");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "years", roundingMode: "halfExpand" }),
/* years = */ 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "years", roundingMode: "halfExpand" }),
/* years = */ -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "months", roundingMode: "halfExpand" }),
0, /* months = */ 32, 0, 0, 0, 0, 0, 0, 0, 0, "months");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "months", roundingMode: "halfExpand" }),
0, /* months = */ -32, 0, 0, 0, 0, 0, 0, 0, 0, "months");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "weeks", roundingMode: "halfExpand" }),
0, 0, /* weeks = */ 139, 0, 0, 0, 0, 0, 0, 0, "weeks");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "weeks", roundingMode: "halfExpand" }),
0, 0, /* weeks = */ -139, 0, 0, 0, 0, 0, 0, 0, "weeks");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "days", roundingMode: "halfExpand" }),
0, 0, 0, /* days = */ 973, 0, 0, 0, 0, 0, 0, "days");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "days", roundingMode: "halfExpand" }),
0, 0, 0, /* days = */ -973, 0, 0, 0, 0, 0, 0, "days");

View File

@ -0,0 +1,40 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaindate.prototype.since
description: Tests calculations with roundingMode "trunc".
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const earlier = Temporal.PlainDate.from("2019-01-08");
const later = Temporal.PlainDate.from("2021-09-07");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "years", roundingMode: "trunc" }),
/* years = */ 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "years", roundingMode: "trunc" }),
/* years = */ -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "months", roundingMode: "trunc" }),
0, /* months = */ 31, 0, 0, 0, 0, 0, 0, 0, 0, "months");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "months", roundingMode: "trunc" }),
0, /* months = */ -31, 0, 0, 0, 0, 0, 0, 0, 0, "months");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "weeks", roundingMode: "trunc" }),
0, 0, /* weeks = */ 139, 0, 0, 0, 0, 0, 0, 0, "weeks");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "weeks", roundingMode: "trunc" }),
0, 0, /* weeks = */ -139, 0, 0, 0, 0, 0, 0, 0, "weeks");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "days", roundingMode: "trunc" }),
0, 0, 0, /* days = */ 973, 0, 0, 0, 0, 0, 0, "days");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "days", roundingMode: "trunc" }),
0, 0, 0, /* days = */ -973, 0, 0, 0, 0, 0, 0, "days");

View File

@ -0,0 +1,24 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaindate.prototype.since
description: Tests calculations with higher smallestUnit than the default of "days"
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
const earlier = Temporal.PlainDate.from("2019-01-08");
const later = Temporal.PlainDate.from("2021-09-07");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "years", roundingMode: "halfExpand" }),
/* years = */ 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "months", roundingMode: "halfExpand" }),
0, /* months = */ 32, 0, 0, 0, 0, 0, 0, 0, 0, "months");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "weeks", roundingMode: "halfExpand" }),
0, 0, /* weeks = */ 139, 0, 0, 0, 0, 0, 0, 0, "weeks");

View File

@ -0,0 +1,16 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaindate.prototype.since
description: since() should not return weeks and months together.
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const date = new Temporal.PlainDate(1969, 7, 24);
const laterDate = new Temporal.PlainDate(1969, 9, 4);
TemporalHelpers.assertDuration(laterDate.since(date, { largestUnit: "weeks" }),
0, 0, /* weeks = */ 6, 0, 0, 0, 0, 0, 0, 0, "weeks");
TemporalHelpers.assertDuration(laterDate.since(date, { largestUnit: "months" }),
0, /* months = */ 1, 0, 11, 0, 0, 0, 0, 0, 0, "months");

View File

@ -0,0 +1,34 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaindate.prototype.until
description: Should round relative to the receiver.
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const date1 = Temporal.PlainDate.from("2019-01-01");
const date2 = Temporal.PlainDate.from("2019-02-15");
TemporalHelpers.assertDuration(
date1.until(date2, { smallestUnit: "months", roundingMode: "halfExpand" }),
0, /* months = */ 2, 0, 0, 0, 0, 0, 0, 0, 0);
TemporalHelpers.assertDuration(
date2.until(date1, { smallestUnit: "months", roundingMode: "halfExpand" }),
0, /* months = */ -1, 0, 0, 0, 0, 0, 0, 0, 0);
const cases = [
["2019-03-01", "2019-01-29", 1, 1],
["2019-01-29", "2019-03-01", -1, -3],
["2019-03-29", "2019-01-30", 1, 29],
["2019-01-30", "2019-03-29", -1, -29],
["2019-03-30", "2019-01-31", 1, 30],
["2019-01-31", "2019-03-30", -1, -28],
["2019-03-31", "2019-01-31", 2, 0],
["2019-01-31", "2019-03-31", -2, 0]
];
for (const [end, start, months, days] of cases) {
const result = Temporal.PlainDate.from(start).until(end, { largestUnit: "months" });
TemporalHelpers.assertDuration(result, 0, months, 0, days, 0, 0, 0, 0, 0, 0, `${end} - ${start}`);
}

View File

@ -0,0 +1,28 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaindate.prototype.until
description: Tests calculations with roundingMode "trunc".
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const earlier = Temporal.PlainDate.from("2019-01-08");
const later = Temporal.PlainDate.from("2021-09-07");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "years", roundingIncrement: 4, roundingMode: "halfExpand" }),
/* years = */ 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "months", roundingIncrement: 10, roundingMode: "halfExpand" }),
0, /* months = */ 30, 0, 0, 0, 0, 0, 0, 0, 0, "months");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "weeks", roundingIncrement: 12, roundingMode: "halfExpand" }),
0, 0, /* weeks = */ 144, 0, 0, 0, 0, 0, 0, 0, "weeks");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "days", roundingIncrement: 100, roundingMode: "halfExpand" }),
0, 0, 0, /* days = */ 1000, 0, 0, 0, 0, 0, 0, "days");

View File

@ -0,0 +1,40 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaindate.prototype.until
description: Tests calculations with roundingMode "ceil".
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const earlier = Temporal.PlainDate.from("2019-01-08");
const later = Temporal.PlainDate.from("2021-09-07");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "years", roundingMode: "ceil" }),
/* years = */ 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "years", roundingMode: "ceil" }),
/* years = */ -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "months", roundingMode: "ceil" }),
0, /* months = */ 32, 0, 0, 0, 0, 0, 0, 0, 0, "months");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "months", roundingMode: "ceil" }),
0, /* months = */ -31, 0, 0, 0, 0, 0, 0, 0, 0, "months");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "weeks", roundingMode: "ceil" }),
0, 0, /* weeks = */ 139, 0, 0, 0, 0, 0, 0, 0, "weeks");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "weeks", roundingMode: "ceil" }),
0, 0, /* weeks = */ -139, 0, 0, 0, 0, 0, 0, 0, "weeks");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "days", roundingMode: "ceil" }),
0, 0, 0, /* days = */ 973, 0, 0, 0, 0, 0, 0, "days");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "days", roundingMode: "ceil" }),
0, 0, 0, /* days = */ -973, 0, 0, 0, 0, 0, 0, "days");

View File

@ -0,0 +1,40 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaindate.prototype.until
description: Tests calculations with roundingMode "floor".
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const earlier = Temporal.PlainDate.from("2019-01-08");
const later = Temporal.PlainDate.from("2021-09-07");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "years", roundingMode: "floor" }),
/* years = */ 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "years", roundingMode: "floor" }),
/* years = */ -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "months", roundingMode: "floor" }),
0, /* months = */ 31, 0, 0, 0, 0, 0, 0, 0, 0, "months");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "months", roundingMode: "floor" }),
0, /* months = */ -32, 0, 0, 0, 0, 0, 0, 0, 0, "months");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "weeks", roundingMode: "floor" }),
0, 0, /* weeks = */ 139, 0, 0, 0, 0, 0, 0, 0, "weeks");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "weeks", roundingMode: "floor" }),
0, 0, /* weeks = */ -139, 0, 0, 0, 0, 0, 0, 0, "weeks");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "days", roundingMode: "floor" }),
0, 0, 0, /* days = */ 973, 0, 0, 0, 0, 0, 0, "days");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "days", roundingMode: "floor" }),
0, 0, 0, /* days = */ -973, 0, 0, 0, 0, 0, 0, "days");

View File

@ -0,0 +1,40 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaindate.prototype.until
description: Tests calculations with roundingMode "halfExpand".
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const earlier = Temporal.PlainDate.from("2019-01-08");
const later = Temporal.PlainDate.from("2021-09-07");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "years", roundingMode: "halfExpand" }),
/* years = */ 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "years", roundingMode: "halfExpand" }),
/* years = */ -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "months", roundingMode: "halfExpand" }),
0, /* months = */ 32, 0, 0, 0, 0, 0, 0, 0, 0, "months");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "months", roundingMode: "halfExpand" }),
0, /* months = */ -32, 0, 0, 0, 0, 0, 0, 0, 0, "months");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "weeks", roundingMode: "halfExpand" }),
0, 0, /* weeks = */ 139, 0, 0, 0, 0, 0, 0, 0, "weeks");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "weeks", roundingMode: "halfExpand" }),
0, 0, /* weeks = */ -139, 0, 0, 0, 0, 0, 0, 0, "weeks");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "days", roundingMode: "halfExpand" }),
0, 0, 0, /* days = */ 973, 0, 0, 0, 0, 0, 0, "days");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "days", roundingMode: "halfExpand" }),
0, 0, 0, /* days = */ -973, 0, 0, 0, 0, 0, 0, "days");

View File

@ -0,0 +1,40 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaindate.prototype.until
description: Tests calculations with roundingMode "trunc".
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const earlier = Temporal.PlainDate.from("2019-01-08");
const later = Temporal.PlainDate.from("2021-09-07");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "years", roundingMode: "trunc" }),
/* years = */ 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "years", roundingMode: "trunc" }),
/* years = */ -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "months", roundingMode: "trunc" }),
0, /* months = */ 31, 0, 0, 0, 0, 0, 0, 0, 0, "months");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "months", roundingMode: "trunc" }),
0, /* months = */ -31, 0, 0, 0, 0, 0, 0, 0, 0, "months");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "weeks", roundingMode: "trunc" }),
0, 0, /* weeks = */ 139, 0, 0, 0, 0, 0, 0, 0, "weeks");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "weeks", roundingMode: "trunc" }),
0, 0, /* weeks = */ -139, 0, 0, 0, 0, 0, 0, 0, "weeks");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "days", roundingMode: "trunc" }),
0, 0, 0, /* days = */ 973, 0, 0, 0, 0, 0, 0, "days");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "days", roundingMode: "trunc" }),
0, 0, 0, /* days = */ -973, 0, 0, 0, 0, 0, 0, "days");

View File

@ -0,0 +1,24 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaindate.prototype.until
description: Tests calculations with higher smallestUnit than the default of "days"
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const earlier = Temporal.PlainDate.from("2019-01-08");
const later = Temporal.PlainDate.from("2021-09-07");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "years", roundingMode: "halfExpand" }),
/* years = */ 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "months", roundingMode: "halfExpand" }),
0, /* months = */ 32, 0, 0, 0, 0, 0, 0, 0, 0, "months");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "weeks", roundingMode: "halfExpand" }),
0, 0, /* weeks = */ 139, 0, 0, 0, 0, 0, 0, 0, "weeks");