summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Temporal/PlainDate/prototype/until/rounding-relative.js
blob: b7b28c9338b795fbef7f91076d84292d84bf0ace (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
// 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}`);
}

reportCompare(0, 0);