mirror of
https://github.com/tc39/test262.git
synced 2025-04-08 19:35:28 +02:00
Temporal: Regularize and expand tests for difference rounding modes
Take all the existing tests for since/until calculations using different rounding modes and standardize them. Add tests for Instant and ZonedDateTime, which were still in the old format in staging.
This commit is contained in:
parent
9c4aed29b7
commit
a788188c2f
39
test/built-ins/Temporal/Instant/prototype/since/roundingmode-ceil.js
vendored
Normal file
39
test/built-ins/Temporal/Instant/prototype/since/roundingmode-ceil.js
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
// 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.instant.prototype.since
|
||||
description: Tests calculations with roundingMode "ceil".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.Instant(217178610_123_456_789n);
|
||||
const later = new Temporal.Instant(1572345998_271_986_102n);
|
||||
|
||||
const expected = [
|
||||
["hours", [0, 0, 0, 0, 376436], [0, 0, 0, 0, -376435]],
|
||||
["minutes", [0, 0, 0, 0, 376435, 24], [0, 0, 0, 0, -376435, -23]],
|
||||
["seconds", [0, 0, 0, 0, 376435, 23, 9], [0, 0, 0, 0, -376435, -23, -8]],
|
||||
["milliseconds", [0, 0, 0, 0, 376435, 23, 8, 149], [0, 0, 0, 0, -376435, -23, -8, -148]],
|
||||
["microseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 530], [0, 0, 0, 0, -376435, -23, -8, -148, -529]],
|
||||
["nanoseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529, 313], [0, 0, 0, 0, -376435, -23, -8, -148, -529, -313]],
|
||||
];
|
||||
|
||||
const roundingMode = "ceil";
|
||||
const largestUnit = "hours";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { largestUnit, smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { largestUnit, smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
39
test/built-ins/Temporal/Instant/prototype/since/roundingmode-floor.js
vendored
Normal file
39
test/built-ins/Temporal/Instant/prototype/since/roundingmode-floor.js
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
// 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.instant.prototype.since
|
||||
description: Tests calculations with roundingMode "floor".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.Instant(217178610_123_456_789n);
|
||||
const later = new Temporal.Instant(1572345998_271_986_102n);
|
||||
|
||||
const expected = [
|
||||
["hours", [0, 0, 0, 0, 376435], [0, 0, 0, 0, -376436]],
|
||||
["minutes", [0, 0, 0, 0, 376435, 23], [0, 0, 0, 0, -376435, -24]],
|
||||
["seconds", [0, 0, 0, 0, 376435, 23, 8], [0, 0, 0, 0, -376435, -23, -9]],
|
||||
["milliseconds", [0, 0, 0, 0, 376435, 23, 8, 148], [0, 0, 0, 0, -376435, -23, -8, -149]],
|
||||
["microseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529], [0, 0, 0, 0, -376435, -23, -8, -148, -530]],
|
||||
["nanoseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529, 313], [0, 0, 0, 0, -376435, -23, -8, -148, -529, -313]],
|
||||
];
|
||||
|
||||
const roundingMode = "floor";
|
||||
const largestUnit = "hours";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { largestUnit, smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { largestUnit, smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
39
test/built-ins/Temporal/Instant/prototype/since/roundingmode-halfExpand.js
vendored
Normal file
39
test/built-ins/Temporal/Instant/prototype/since/roundingmode-halfExpand.js
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
// 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.instant.prototype.since
|
||||
description: Tests calculations with roundingMode "halfExpand".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.Instant(217178610_123_456_789n);
|
||||
const later = new Temporal.Instant(1572345998_271_986_102n);
|
||||
|
||||
const expected = [
|
||||
["hours", [0, 0, 0, 0, 376435], [0, 0, 0, 0, -376435]],
|
||||
["minutes", [0, 0, 0, 0, 376435, 23], [0, 0, 0, 0, -376435, -23]],
|
||||
["seconds", [0, 0, 0, 0, 376435, 23, 8], [0, 0, 0, 0, -376435, -23, -8]],
|
||||
["milliseconds", [0, 0, 0, 0, 376435, 23, 8, 149], [0, 0, 0, 0, -376435, -23, -8, -149]],
|
||||
["microseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529], [0, 0, 0, 0, -376435, -23, -8, -148, -529]],
|
||||
["nanoseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529, 313], [0, 0, 0, 0, -376435, -23, -8, -148, -529, -313]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfExpand";
|
||||
const largestUnit = "hours";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { largestUnit, smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { largestUnit, smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
39
test/built-ins/Temporal/Instant/prototype/since/roundingmode-trunc.js
vendored
Normal file
39
test/built-ins/Temporal/Instant/prototype/since/roundingmode-trunc.js
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
// 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.instant.prototype.since
|
||||
description: Tests calculations with roundingMode "trunc".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.Instant(217178610_123_456_789n);
|
||||
const later = new Temporal.Instant(1572345998_271_986_102n);
|
||||
|
||||
const expected = [
|
||||
["hours", [0, 0, 0, 0, 376435], [0, 0, 0, 0, -376435]],
|
||||
["minutes", [0, 0, 0, 0, 376435, 23], [0, 0, 0, 0, -376435, -23]],
|
||||
["seconds", [0, 0, 0, 0, 376435, 23, 8], [0, 0, 0, 0, -376435, -23, -8]],
|
||||
["milliseconds", [0, 0, 0, 0, 376435, 23, 8, 148], [0, 0, 0, 0, -376435, -23, -8, -148]],
|
||||
["microseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529], [0, 0, 0, 0, -376435, -23, -8, -148, -529]],
|
||||
["nanoseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529, 313], [0, 0, 0, 0, -376435, -23, -8, -148, -529, -313]],
|
||||
];
|
||||
|
||||
const roundingMode = "trunc";
|
||||
const largestUnit = "hours";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { largestUnit, smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { largestUnit, smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
39
test/built-ins/Temporal/Instant/prototype/until/roundingmode-ceil.js
vendored
Normal file
39
test/built-ins/Temporal/Instant/prototype/until/roundingmode-ceil.js
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
// 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.instant.prototype.until
|
||||
description: Tests calculations with roundingMode "ceil".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.Instant(217178610_123_456_789n);
|
||||
const later = new Temporal.Instant(1572345998_271_986_102n);
|
||||
|
||||
const expected = [
|
||||
["hours", [0, 0, 0, 0, 376436], [0, 0, 0, 0, -376435]],
|
||||
["minutes", [0, 0, 0, 0, 376435, 24], [0, 0, 0, 0, -376435, -23]],
|
||||
["seconds", [0, 0, 0, 0, 376435, 23, 9], [0, 0, 0, 0, -376435, -23, -8]],
|
||||
["milliseconds", [0, 0, 0, 0, 376435, 23, 8, 149], [0, 0, 0, 0, -376435, -23, -8, -148]],
|
||||
["microseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 530], [0, 0, 0, 0, -376435, -23, -8, -148, -529]],
|
||||
["nanoseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529, 313], [0, 0, 0, 0, -376435, -23, -8, -148, -529, -313]],
|
||||
];
|
||||
|
||||
const roundingMode = "ceil";
|
||||
const largestUnit = "hours";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { largestUnit, smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { largestUnit, smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
39
test/built-ins/Temporal/Instant/prototype/until/roundingmode-floor.js
vendored
Normal file
39
test/built-ins/Temporal/Instant/prototype/until/roundingmode-floor.js
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
// 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.instant.prototype.until
|
||||
description: Tests calculations with roundingMode "floor".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.Instant(217178610_123_456_789n);
|
||||
const later = new Temporal.Instant(1572345998_271_986_102n);
|
||||
|
||||
const expected = [
|
||||
["hours", [0, 0, 0, 0, 376435], [0, 0, 0, 0, -376436]],
|
||||
["minutes", [0, 0, 0, 0, 376435, 23], [0, 0, 0, 0, -376435, -24]],
|
||||
["seconds", [0, 0, 0, 0, 376435, 23, 8], [0, 0, 0, 0, -376435, -23, -9]],
|
||||
["milliseconds", [0, 0, 0, 0, 376435, 23, 8, 148], [0, 0, 0, 0, -376435, -23, -8, -149]],
|
||||
["microseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529], [0, 0, 0, 0, -376435, -23, -8, -148, -530]],
|
||||
["nanoseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529, 313], [0, 0, 0, 0, -376435, -23, -8, -148, -529, -313]],
|
||||
];
|
||||
|
||||
const roundingMode = "floor";
|
||||
const largestUnit = "hours";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { largestUnit, smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { largestUnit, smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
39
test/built-ins/Temporal/Instant/prototype/until/roundingmode-halfExpand.js
vendored
Normal file
39
test/built-ins/Temporal/Instant/prototype/until/roundingmode-halfExpand.js
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
// 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.instant.prototype.until
|
||||
description: Tests calculations with roundingMode "halfExpand".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.Instant(217178610_123_456_789n);
|
||||
const later = new Temporal.Instant(1572345998_271_986_102n);
|
||||
|
||||
const expected = [
|
||||
["hours", [0, 0, 0, 0, 376435], [0, 0, 0, 0, -376435]],
|
||||
["minutes", [0, 0, 0, 0, 376435, 23], [0, 0, 0, 0, -376435, -23]],
|
||||
["seconds", [0, 0, 0, 0, 376435, 23, 8], [0, 0, 0, 0, -376435, -23, -8]],
|
||||
["milliseconds", [0, 0, 0, 0, 376435, 23, 8, 149], [0, 0, 0, 0, -376435, -23, -8, -149]],
|
||||
["microseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529], [0, 0, 0, 0, -376435, -23, -8, -148, -529]],
|
||||
["nanoseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529, 313], [0, 0, 0, 0, -376435, -23, -8, -148, -529, -313]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfExpand";
|
||||
const largestUnit = "hours";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { largestUnit, smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { largestUnit, smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
39
test/built-ins/Temporal/Instant/prototype/until/roundingmode-trunc.js
vendored
Normal file
39
test/built-ins/Temporal/Instant/prototype/until/roundingmode-trunc.js
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
// 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.instant.prototype.until
|
||||
description: Tests calculations with roundingMode "trunc".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.Instant(217178610_123_456_789n);
|
||||
const later = new Temporal.Instant(1572345998_271_986_102n);
|
||||
|
||||
const expected = [
|
||||
["hours", [0, 0, 0, 0, 376435], [0, 0, 0, 0, -376435]],
|
||||
["minutes", [0, 0, 0, 0, 376435, 23], [0, 0, 0, 0, -376435, -23]],
|
||||
["seconds", [0, 0, 0, 0, 376435, 23, 8], [0, 0, 0, 0, -376435, -23, -8]],
|
||||
["milliseconds", [0, 0, 0, 0, 376435, 23, 8, 148], [0, 0, 0, 0, -376435, -23, -8, -148]],
|
||||
["microseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529], [0, 0, 0, 0, -376435, -23, -8, -148, -529]],
|
||||
["nanoseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529, 313], [0, 0, 0, 0, -376435, -23, -8, -148, -529, -313]],
|
||||
];
|
||||
|
||||
const roundingMode = "trunc";
|
||||
const largestUnit = "hours";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { largestUnit, smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { largestUnit, smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
@ -8,33 +8,29 @@ includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = Temporal.PlainDate.from("2019-01-08");
|
||||
const later = Temporal.PlainDate.from("2021-09-07");
|
||||
const earlier = new Temporal.PlainDate(2019, 1, 8);
|
||||
const later = new Temporal.PlainDate(2021, 9, 7);
|
||||
|
||||
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");
|
||||
const expected = [
|
||||
["years", [3], [-2]],
|
||||
["months", [0, 32], [0, -31]],
|
||||
["weeks", [0, 0, 139], [0, 0, -139]],
|
||||
["days", [0, 0, 0, 973], [0, 0, 0, -973]],
|
||||
];
|
||||
|
||||
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");
|
||||
const roundingMode = "ceil";
|
||||
|
||||
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");
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
||||
|
@ -8,33 +8,29 @@ includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = Temporal.PlainDate.from("2019-01-08");
|
||||
const later = Temporal.PlainDate.from("2021-09-07");
|
||||
const earlier = new Temporal.PlainDate(2019, 1, 8);
|
||||
const later = new Temporal.PlainDate(2021, 9, 7);
|
||||
|
||||
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");
|
||||
const expected = [
|
||||
["years", [2], [-3]],
|
||||
["months", [0, 31], [0, -32]],
|
||||
["weeks", [0, 0, 139], [0, 0, -139]],
|
||||
["days", [0, 0, 0, 973], [0, 0, 0, -973]],
|
||||
];
|
||||
|
||||
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");
|
||||
const roundingMode = "floor";
|
||||
|
||||
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");
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
||||
|
@ -8,33 +8,29 @@ includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = Temporal.PlainDate.from("2019-01-08");
|
||||
const later = Temporal.PlainDate.from("2021-09-07");
|
||||
const earlier = new Temporal.PlainDate(2019, 1, 8);
|
||||
const later = new Temporal.PlainDate(2021, 9, 7);
|
||||
|
||||
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");
|
||||
const expected = [
|
||||
["years", [3], [-3]],
|
||||
["months", [0, 32], [0, -32]],
|
||||
["weeks", [0, 0, 139], [0, 0, -139]],
|
||||
["days", [0, 0, 0, 973], [0, 0, 0, -973]],
|
||||
];
|
||||
|
||||
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");
|
||||
const roundingMode = "halfExpand";
|
||||
|
||||
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");
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
||||
|
@ -8,33 +8,29 @@ includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = Temporal.PlainDate.from("2019-01-08");
|
||||
const later = Temporal.PlainDate.from("2021-09-07");
|
||||
const earlier = new Temporal.PlainDate(2019, 1, 8);
|
||||
const later = new Temporal.PlainDate(2021, 9, 7);
|
||||
|
||||
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");
|
||||
const expected = [
|
||||
["years", [2], [-2]],
|
||||
["months", [0, 31], [0, -31]],
|
||||
["weeks", [0, 0, 139], [0, 0, -139]],
|
||||
["days", [0, 0, 0, 973], [0, 0, 0, -973]],
|
||||
];
|
||||
|
||||
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");
|
||||
const roundingMode = "trunc";
|
||||
|
||||
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");
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
||||
|
@ -8,33 +8,29 @@ includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = Temporal.PlainDate.from("2019-01-08");
|
||||
const later = Temporal.PlainDate.from("2021-09-07");
|
||||
const earlier = new Temporal.PlainDate(2019, 1, 8);
|
||||
const later = new Temporal.PlainDate(2021, 9, 7);
|
||||
|
||||
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");
|
||||
const expected = [
|
||||
["years", [3], [-2]],
|
||||
["months", [0, 32], [0, -31]],
|
||||
["weeks", [0, 0, 139], [0, 0, -139]],
|
||||
["days", [0, 0, 0, 973], [0, 0, 0, -973]],
|
||||
];
|
||||
|
||||
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");
|
||||
const roundingMode = "ceil";
|
||||
|
||||
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");
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
||||
|
@ -8,33 +8,29 @@ includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = Temporal.PlainDate.from("2019-01-08");
|
||||
const later = Temporal.PlainDate.from("2021-09-07");
|
||||
const earlier = new Temporal.PlainDate(2019, 1, 8);
|
||||
const later = new Temporal.PlainDate(2021, 9, 7);
|
||||
|
||||
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");
|
||||
const expected = [
|
||||
["years", [2], [-3]],
|
||||
["months", [0, 31], [0, -32]],
|
||||
["weeks", [0, 0, 139], [0, 0, -139]],
|
||||
["days", [0, 0, 0, 973], [0, 0, 0, -973]],
|
||||
];
|
||||
|
||||
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");
|
||||
const roundingMode = "floor";
|
||||
|
||||
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");
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
||||
|
@ -8,33 +8,29 @@ includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = Temporal.PlainDate.from("2019-01-08");
|
||||
const later = Temporal.PlainDate.from("2021-09-07");
|
||||
const earlier = new Temporal.PlainDate(2019, 1, 8);
|
||||
const later = new Temporal.PlainDate(2021, 9, 7);
|
||||
|
||||
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");
|
||||
const expected = [
|
||||
["years", [3], [-3]],
|
||||
["months", [0, 32], [0, -32]],
|
||||
["weeks", [0, 0, 139], [0, 0, -139]],
|
||||
["days", [0, 0, 0, 973], [0, 0, 0, -973]],
|
||||
];
|
||||
|
||||
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");
|
||||
const roundingMode = "halfExpand";
|
||||
|
||||
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");
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
||||
|
@ -8,33 +8,29 @@ includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = Temporal.PlainDate.from("2019-01-08");
|
||||
const later = Temporal.PlainDate.from("2021-09-07");
|
||||
const earlier = new Temporal.PlainDate(2019, 1, 8);
|
||||
const later = new Temporal.PlainDate(2021, 9, 7);
|
||||
|
||||
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");
|
||||
const expected = [
|
||||
["years", [2], [-2]],
|
||||
["months", [0, 31], [0, -31]],
|
||||
["weeks", [0, 0, 139], [0, 0, -139]],
|
||||
["days", [0, 0, 0, 973], [0, 0, 0, -973]],
|
||||
];
|
||||
|
||||
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");
|
||||
const roundingMode = "trunc";
|
||||
|
||||
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");
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
||||
|
@ -2,16 +2,16 @@
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindatetime.prototype.until
|
||||
description: Checking that ceiling rounding mode rounds correctly
|
||||
features: [Temporal]
|
||||
esid: sec-temporal.plaindatetime.prototype.since
|
||||
description: Tests calculations with roundingMode "ceil".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainDateTime(2019, 1, 8, 8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainDateTime(2021, 9, 7, 12, 39, 40, 987, 654, 321);
|
||||
|
||||
const incrementOneCeil = [
|
||||
const expected = [
|
||||
["years", [3], [-2]],
|
||||
["months", [0, 32], [0, -31]],
|
||||
["weeks", [0, 0, 140], [0, 0, -139]],
|
||||
@ -21,19 +21,22 @@ const incrementOneCeil = [
|
||||
["seconds", [0, 0, 0, 973, 4, 17, 5], [0, 0, 0, -973, -4, -17, -4]],
|
||||
["milliseconds", [0, 0, 0, 973, 4, 17, 4, 865], [0, 0, 0, -973, -4, -17, -4, -864]],
|
||||
["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 198], [0, 0, 0, -973, -4, -17, -4, -864, -197]],
|
||||
["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]]
|
||||
["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]],
|
||||
];
|
||||
incrementOneCeil.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
|
||||
const roundingMode = "ceil";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit, roundingMode: "ceil" }),
|
||||
later.since(earlier, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds up to ${smallestUnit} (roundingMode = ceil, positive case)`
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, {smallestUnit, roundingMode: "ceil"}),
|
||||
earlier.since(later, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds up to ${smallestUnit} (rounding mode = ceil, negative case)`
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
@ -3,7 +3,7 @@
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindatetime.prototype.since
|
||||
description: Floor rounding mode basic tests
|
||||
description: Tests calculations with roundingMode "floor".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
@ -11,7 +11,7 @@ features: [Temporal]
|
||||
const earlier = new Temporal.PlainDateTime(2019, 1, 8, 8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainDateTime(2021, 9, 7, 12, 39, 40, 987, 654, 321);
|
||||
|
||||
const incrementOneFloor = [
|
||||
const expected = [
|
||||
["years", [2], [-3]],
|
||||
["months", [0, 31], [0, -32]],
|
||||
["weeks", [0, 0, 139], [0, 0, -140]],
|
||||
@ -21,22 +21,22 @@ const incrementOneFloor = [
|
||||
["seconds", [0, 0, 0, 973, 4, 17, 4], [0, 0, 0, -973, -4, -17, -5]],
|
||||
["milliseconds", [0, 0, 0, 973, 4, 17, 4, 864], [0, 0, 0, -973, -4, -17, -4, -865]],
|
||||
["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197], [0, 0, 0, -973, -4, -17, -4, -864, -198]],
|
||||
["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]]
|
||||
["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]],
|
||||
];
|
||||
|
||||
const roundingMode = "floor";
|
||||
|
||||
incrementOneFloor.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds down to ${smallestUnit} (rounding mode = ${roundingMode}, positive case)`
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds down to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
42
test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-halfExpand.js
vendored
Normal file
42
test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-halfExpand.js
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
// 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.plaindatetime.prototype.since
|
||||
description: Tests calculations with roundingMode "halfExpand".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainDateTime(2019, 1, 8, 8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainDateTime(2021, 9, 7, 12, 39, 40, 987, 654, 321);
|
||||
|
||||
const expected = [
|
||||
["years", [3], [-3]],
|
||||
["months", [0, 32], [0, -32]],
|
||||
["weeks", [0, 0, 139], [0, 0, -139]],
|
||||
["days", [0, 0, 0, 973], [0, 0, 0, -973]],
|
||||
["hours", [0, 0, 0, 973, 4], [0, 0, 0, -973, -4]],
|
||||
["minutes", [0, 0, 0, 973, 4, 17], [0, 0, 0, -973, -4, -17]],
|
||||
["seconds", [0, 0, 0, 973, 4, 17, 5], [0, 0, 0, -973, -4, -17, -5]],
|
||||
["milliseconds", [0, 0, 0, 973, 4, 17, 4, 864], [0, 0, 0, -973, -4, -17, -4, -864]],
|
||||
["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 198], [0, 0, 0, -973, -4, -17, -4, -864, -198]],
|
||||
["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfExpand";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
@ -1,52 +0,0 @@
|
||||
// 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.plaindatetime.prototype.since
|
||||
description: Half-expand rounding mode basic tests
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainDateTime(2019, 1, 8, 8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainDateTime(2021, 9, 7, 12, 39, 40, 987, 654, 321);
|
||||
|
||||
function ensureUnsignedZero(x) {
|
||||
return Object.is(x, -0) ? 0 : x;
|
||||
}
|
||||
|
||||
const incrementOneNearest = [
|
||||
["years", [3]],
|
||||
["months", [0, 32]],
|
||||
["weeks", [0, 0, 139]],
|
||||
["days", [0, 0, 0, 973]],
|
||||
["hours", [0, 0, 0, 973, 4]],
|
||||
["minutes", [0, 0, 0, 973, 4, 17]],
|
||||
["seconds", [0, 0, 0, 973, 4, 17, 5]],
|
||||
["milliseconds", [0, 0, 0, 973, 4, 17, 4, 864]],
|
||||
["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 198]],
|
||||
["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532]]
|
||||
];
|
||||
const roundingMode = "halfExpand";
|
||||
incrementOneNearest.forEach(([smallestUnit, expected]) => {
|
||||
const [y, m = 0, w = 0, d = 0, h = 0, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected;
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit, roundingMode }),
|
||||
y, m, w, d, h, min, s, ms, µs, ns,
|
||||
`rounds to nearest ${smallestUnit} (rounding mode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit, roundingMode }),
|
||||
ensureUnsignedZero(-y),
|
||||
ensureUnsignedZero(-m),
|
||||
ensureUnsignedZero(-w),
|
||||
ensureUnsignedZero(-d),
|
||||
ensureUnsignedZero(-h),
|
||||
ensureUnsignedZero(-min),
|
||||
ensureUnsignedZero(-s),
|
||||
ensureUnsignedZero(-ms),
|
||||
ensureUnsignedZero(-µs),
|
||||
ensureUnsignedZero(-ns),
|
||||
`rounds to nearest ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
@ -1,54 +0,0 @@
|
||||
// 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.plaindatetime.prototype.since
|
||||
description: Truncation rounding mode basic tests
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainDateTime(2019, 1, 8, 8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainDateTime(2021, 9, 7, 12, 39, 40, 987, 654, 321);
|
||||
|
||||
function ensureUnsignedZero(x) {
|
||||
return Object.is(x, -0) ? 0 : x;
|
||||
}
|
||||
|
||||
const incrementOneTrunc = [
|
||||
["years", [2]],
|
||||
["months", [0, 31]],
|
||||
["weeks", [0, 0, 139]],
|
||||
["days", [0, 0, 0, 973]],
|
||||
["hours", [0, 0, 0, 973, 4]],
|
||||
["minutes", [0, 0, 0, 973, 4, 17]],
|
||||
["seconds", [0, 0, 0, 973, 4, 17, 4]],
|
||||
["milliseconds", [0, 0, 0, 973, 4, 17, 4, 864]],
|
||||
["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197]],
|
||||
["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532]]
|
||||
];
|
||||
|
||||
const roundingMode = "trunc";
|
||||
|
||||
incrementOneTrunc.forEach(([smallestUnit, expected]) => {
|
||||
const [y, m = 0, w = 0, d = 0, h = 0, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected;
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit, roundingMode }),
|
||||
y, m, w, d, h, min, s, ms, µs, ns,
|
||||
`truncates to ${smallestUnit} (rounding mode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit, roundingMode }),
|
||||
ensureUnsignedZero(-y),
|
||||
ensureUnsignedZero(-m),
|
||||
ensureUnsignedZero(-w),
|
||||
ensureUnsignedZero(-d),
|
||||
ensureUnsignedZero(-h),
|
||||
ensureUnsignedZero(-min),
|
||||
ensureUnsignedZero(-s),
|
||||
ensureUnsignedZero(-ms),
|
||||
ensureUnsignedZero(-µs),
|
||||
ensureUnsignedZero(-ns),
|
||||
`truncates to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
42
test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-trunc.js
vendored
Normal file
42
test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-trunc.js
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
// 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.plaindatetime.prototype.since
|
||||
description: Tests calculations with roundingMode "trunc".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainDateTime(2019, 1, 8, 8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainDateTime(2021, 9, 7, 12, 39, 40, 987, 654, 321);
|
||||
|
||||
const expected = [
|
||||
["years", [2], [-2]],
|
||||
["months", [0, 31], [0, -31]],
|
||||
["weeks", [0, 0, 139], [0, 0, -139]],
|
||||
["days", [0, 0, 0, 973], [0, 0, 0, -973]],
|
||||
["hours", [0, 0, 0, 973, 4], [0, 0, 0, -973, -4]],
|
||||
["minutes", [0, 0, 0, 973, 4, 17], [0, 0, 0, -973, -4, -17]],
|
||||
["seconds", [0, 0, 0, 973, 4, 17, 4], [0, 0, 0, -973, -4, -17, -4]],
|
||||
["milliseconds", [0, 0, 0, 973, 4, 17, 4, 864], [0, 0, 0, -973, -4, -17, -4, -864]],
|
||||
["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197], [0, 0, 0, -973, -4, -17, -4, -864, -197]],
|
||||
["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]],
|
||||
];
|
||||
|
||||
const roundingMode = "trunc";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
@ -2,8 +2,8 @@
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindatetime.prototype.since
|
||||
description: Ceiling rounding mode basic tests
|
||||
esid: sec-temporal.plaindatetime.prototype.until
|
||||
description: Tests calculations with roundingMode "ceil".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
@ -11,7 +11,7 @@ features: [Temporal]
|
||||
const earlier = new Temporal.PlainDateTime(2019, 1, 8, 8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainDateTime(2021, 9, 7, 12, 39, 40, 987, 654, 321);
|
||||
|
||||
const incrementOneCeil = [
|
||||
const expected = [
|
||||
["years", [3], [-2]],
|
||||
["months", [0, 32], [0, -31]],
|
||||
["weeks", [0, 0, 140], [0, 0, -139]],
|
||||
@ -21,20 +21,22 @@ const incrementOneCeil = [
|
||||
["seconds", [0, 0, 0, 973, 4, 17, 5], [0, 0, 0, -973, -4, -17, -4]],
|
||||
["milliseconds", [0, 0, 0, 973, 4, 17, 4, 865], [0, 0, 0, -973, -4, -17, -4, -864]],
|
||||
["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 198], [0, 0, 0, -973, -4, -17, -4, -864, -197]],
|
||||
["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]]
|
||||
["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]],
|
||||
];
|
||||
|
||||
const roundingMode = "ceil";
|
||||
incrementOneCeil.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds up to ${smallestUnit} (roundingMode = ceil, positive case)`
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds up to ${smallestUnit} (rounding mode = ceil, negative case)`
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
@ -3,15 +3,15 @@
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindatetime.prototype.until
|
||||
description: Checking that floor rounding mode rounds correctly
|
||||
features: [Temporal]
|
||||
description: Tests calculations with roundingMode "floor".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainDateTime(2019, 1, 8, 8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainDateTime(2021, 9, 7, 12, 39, 40, 987, 654, 321);
|
||||
|
||||
const incrementOneFloor = [
|
||||
const expected = [
|
||||
["years", [2], [-3]],
|
||||
["months", [0, 31], [0, -32]],
|
||||
["weeks", [0, 0, 139], [0, 0, -140]],
|
||||
@ -21,19 +21,22 @@ const incrementOneFloor = [
|
||||
["seconds", [0, 0, 0, 973, 4, 17, 4], [0, 0, 0, -973, -4, -17, -5]],
|
||||
["milliseconds", [0, 0, 0, 973, 4, 17, 4, 864], [0, 0, 0, -973, -4, -17, -4, -865]],
|
||||
["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197], [0, 0, 0, -973, -4, -17, -4, -864, -198]],
|
||||
["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]]
|
||||
["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]],
|
||||
];
|
||||
incrementOneFloor.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
|
||||
const roundingMode = "floor";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit, roundingMode: "floor" }),
|
||||
earlier.until(later, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds down to ${smallestUnit} (rounding mode = floor, positive case)`
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, {smallestUnit, roundingMode: "floor"}),
|
||||
later.until(earlier, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds down to ${smallestUnit} (rounding mode = floor, negative case)`
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
42
test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-halfExpand.js
vendored
Normal file
42
test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-halfExpand.js
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
// 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.plaindatetime.prototype.until
|
||||
description: Tests calculations with roundingMode "halfExpand".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainDateTime(2019, 1, 8, 8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainDateTime(2021, 9, 7, 12, 39, 40, 987, 654, 321);
|
||||
|
||||
const expected = [
|
||||
["years", [3], [-3]],
|
||||
["months", [0, 32], [0, -32]],
|
||||
["weeks", [0, 0, 139], [0, 0, -139]],
|
||||
["days", [0, 0, 0, 973], [0, 0, 0, -973]],
|
||||
["hours", [0, 0, 0, 973, 4], [0, 0, 0, -973, -4]],
|
||||
["minutes", [0, 0, 0, 973, 4, 17], [0, 0, 0, -973, -4, -17]],
|
||||
["seconds", [0, 0, 0, 973, 4, 17, 5], [0, 0, 0, -973, -4, -17, -5]],
|
||||
["milliseconds", [0, 0, 0, 973, 4, 17, 4, 864], [0, 0, 0, -973, -4, -17, -4, -864]],
|
||||
["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 198], [0, 0, 0, -973, -4, -17, -4, -864, -198]],
|
||||
["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfExpand";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
@ -1,51 +0,0 @@
|
||||
// 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.plaindatetime.prototype.until
|
||||
description: Checking that half-expand rounding mode rounds correctly
|
||||
features: [Temporal]
|
||||
includes: [temporalHelpers.js]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainDateTime(2019, 1, 8, 8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainDateTime(2021, 9, 7, 12, 39, 40, 987, 654, 321);
|
||||
|
||||
function ensureUnsignedZero(x) {
|
||||
return Object.is(x, -0) ? 0 : x;
|
||||
}
|
||||
|
||||
const incrementOneNearest = [
|
||||
["years", [3]],
|
||||
["months", [0, 32]],
|
||||
["weeks", [0, 0, 139]],
|
||||
["days", [0, 0, 0, 973]],
|
||||
["hours", [0, 0, 0, 973, 4]],
|
||||
["minutes", [0, 0, 0, 973, 4, 17]],
|
||||
["seconds", [0, 0, 0, 973, 4, 17, 5]],
|
||||
["milliseconds", [0, 0, 0, 973, 4, 17, 4, 864]],
|
||||
["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 198]],
|
||||
["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532]]
|
||||
];
|
||||
incrementOneNearest.forEach(([smallestUnit, expected]) => {
|
||||
const [y, m = 0, w = 0, d = 0, h = 0, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, {smallestUnit, roundingMode: "halfExpand"}),
|
||||
y, m, w, d, h, min, s, ms, µs, ns,
|
||||
`rounds to nearest ${smallestUnit} (positive case, rounding mode = halfExpand)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, {smallestUnit, roundingMode: "halfExpand"}),
|
||||
ensureUnsignedZero(-y),
|
||||
ensureUnsignedZero(-m),
|
||||
ensureUnsignedZero(-w),
|
||||
ensureUnsignedZero(-d),
|
||||
ensureUnsignedZero(-h),
|
||||
ensureUnsignedZero(-min),
|
||||
ensureUnsignedZero(-s),
|
||||
ensureUnsignedZero(-ms),
|
||||
ensureUnsignedZero(-µs),
|
||||
ensureUnsignedZero(-ns),
|
||||
`rounds to nearest ${smallestUnit} (negative case, rounding mode = halfExpand)`
|
||||
);
|
||||
});
|
@ -1,51 +0,0 @@
|
||||
// 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.plaindatetime.prototype.until
|
||||
description: A variety of tests for truncation (trunc) round mode
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainDateTime(2019, 1, 8, 8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainDateTime(2021, 9, 7, 12, 39, 40, 987, 654, 321);
|
||||
|
||||
function ensureUnsignedZero(x) {
|
||||
return Object.is(x, -0) ? 0 : x;
|
||||
}
|
||||
|
||||
const incrementOneTrunc = [
|
||||
["years", [2]],
|
||||
["months", [0, 31]],
|
||||
["weeks", [0, 0, 139]],
|
||||
["days", [0, 0, 0, 973]],
|
||||
["hours", [0, 0, 0, 973, 4]],
|
||||
["minutes", [0, 0, 0, 973, 4, 17]],
|
||||
["seconds", [0, 0, 0, 973, 4, 17, 4]],
|
||||
["milliseconds", [0, 0, 0, 973, 4, 17, 4, 864]],
|
||||
["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197]],
|
||||
["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532]]
|
||||
];
|
||||
incrementOneTrunc.forEach(([smallestUnit, expected]) => {
|
||||
const [y, m = 0, w = 0, d = 0, h = 0, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, {smallestUnit, roundingMode: "trunc"}),
|
||||
y, m, w, d, h, min, s, ms, µs, ns,
|
||||
`truncates to ${smallestUnit} (rounding mode = trunc, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, {smallestUnit, roundingMode: "trunc"}),
|
||||
ensureUnsignedZero(-y),
|
||||
ensureUnsignedZero(-m),
|
||||
ensureUnsignedZero(-w),
|
||||
ensureUnsignedZero(-d),
|
||||
ensureUnsignedZero(-h),
|
||||
ensureUnsignedZero(-min),
|
||||
ensureUnsignedZero(-s),
|
||||
ensureUnsignedZero(-ms),
|
||||
ensureUnsignedZero(-µs),
|
||||
ensureUnsignedZero(-ns),
|
||||
`truncates to ${smallestUnit} (rounding mode = trunc, negative case)`
|
||||
);
|
||||
});
|
42
test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-trunc.js
vendored
Normal file
42
test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-trunc.js
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
// 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.plaindatetime.prototype.until
|
||||
description: Tests calculations with roundingMode "trunc".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainDateTime(2019, 1, 8, 8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainDateTime(2021, 9, 7, 12, 39, 40, 987, 654, 321);
|
||||
|
||||
const expected = [
|
||||
["years", [2], [-2]],
|
||||
["months", [0, 31], [0, -31]],
|
||||
["weeks", [0, 0, 139], [0, 0, -139]],
|
||||
["days", [0, 0, 0, 973], [0, 0, 0, -973]],
|
||||
["hours", [0, 0, 0, 973, 4], [0, 0, 0, -973, -4]],
|
||||
["minutes", [0, 0, 0, 973, 4, 17], [0, 0, 0, -973, -4, -17]],
|
||||
["seconds", [0, 0, 0, 973, 4, 17, 4], [0, 0, 0, -973, -4, -17, -4]],
|
||||
["milliseconds", [0, 0, 0, 973, 4, 17, 4, 864], [0, 0, 0, -973, -4, -17, -4, -864]],
|
||||
["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197], [0, 0, 0, -973, -4, -17, -4, -864, -197]],
|
||||
["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]],
|
||||
];
|
||||
|
||||
const roundingMode = "trunc";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
@ -8,47 +8,31 @@ includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = Temporal.PlainTime.from("08:22:36.123456789");
|
||||
const later = Temporal.PlainTime.from("12:39:40.987654321");
|
||||
const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321);
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "hours", roundingMode: "ceil" }),
|
||||
0, 0, 0, 0, 5, 0, 0, 0, 0, 0, "hours");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "hours", roundingMode: "ceil" }),
|
||||
0, 0, 0, 0, -4, 0, 0, 0, 0, 0, "hours");
|
||||
const expected = [
|
||||
["hours", [0, 0, 0, 0, 5], [0, 0, 0, 0, -4]],
|
||||
["minutes", [0, 0, 0, 0, 4, 18], [0, 0, 0, 0, -4, -17]],
|
||||
["seconds", [0, 0, 0, 0, 4, 17, 5], [0, 0, 0, 0, -4, -17, -4]],
|
||||
["milliseconds", [0, 0, 0, 0, 4, 17, 4, 865], [0, 0, 0, 0, -4, -17, -4, -864]],
|
||||
["microseconds", [0, 0, 0, 0, 4, 17, 4, 864, 198], [0, 0, 0, 0, -4, -17, -4, -864, -197]],
|
||||
["nanoseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197, 532], [0, 0, 0, 0, -4, -17, -4, -864, -197, -532]],
|
||||
];
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "minutes", roundingMode: "ceil" }),
|
||||
0, 0, 0, 0, 4, 18, 0, 0, 0, 0, "minutes");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "minutes", roundingMode: "ceil" }),
|
||||
0, 0, 0, 0, -4, -17, 0, 0, 0, 0, "minutes");
|
||||
const roundingMode = "ceil";
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "seconds", roundingMode: "ceil" }),
|
||||
0, 0, 0, 0, 4, 17, 5, 0, 0, 0, "seconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "seconds", roundingMode: "ceil" }),
|
||||
0, 0, 0, 0, -4, -17, -4, 0, 0, 0, "seconds");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "milliseconds", roundingMode: "ceil" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 865, 0, 0, "milliseconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "milliseconds", roundingMode: "ceil" }),
|
||||
0, 0, 0, 0, -4, -17, -4, -864, 0, 0, "milliseconds");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "microseconds", roundingMode: "ceil" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 864, 198, 0, "microseconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "microseconds", roundingMode: "ceil" }),
|
||||
0, 0, 0, 0, -4, -17, -4, -864, -197, 0, "microseconds");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "nanoseconds", roundingMode: "ceil" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "nanoseconds", roundingMode: "ceil" }),
|
||||
0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds");
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
||||
|
@ -8,48 +8,31 @@ includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = Temporal.PlainTime.from("08:22:36.123456789");
|
||||
const later = Temporal.PlainTime.from("12:39:40.987654321");
|
||||
const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321);
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "hours", roundingMode: "floor" }),
|
||||
0, 0, 0, 0, 4, 0, 0, 0, 0, 0, "hours");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "hours", roundingMode: "floor" }),
|
||||
0, 0, 0, 0, -5, 0, 0, 0, 0, 0, "hours");
|
||||
const expected = [
|
||||
["hours", [0, 0, 0, 0, 4], [0, 0, 0, 0, -5]],
|
||||
["minutes", [0, 0, 0, 0, 4, 17], [0, 0, 0, 0, -4, -18]],
|
||||
["seconds", [0, 0, 0, 0, 4, 17, 4], [0, 0, 0, 0, -4, -17, -5]],
|
||||
["milliseconds", [0, 0, 0, 0, 4, 17, 4, 864], [0, 0, 0, 0, -4, -17, -4, -865]],
|
||||
["microseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197], [0, 0, 0, 0, -4, -17, -4, -864, -198]],
|
||||
["nanoseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197, 532], [0, 0, 0, 0, -4, -17, -4, -864, -197, -532]],
|
||||
];
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "minutes", roundingMode: "floor" }),
|
||||
0, 0, 0, 0, 4, 17, 0, 0, 0, 0, "minutes");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "minutes", roundingMode: "floor" }),
|
||||
0, 0, 0, 0, -4, -18, 0, 0, 0, 0, "minutes");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "seconds", roundingMode: "floor" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 0, 0, 0, "seconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "seconds", roundingMode: "floor" }),
|
||||
0, 0, 0, 0, -4, -17, -5, 0, 0, 0, "seconds");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "milliseconds", roundingMode: "floor" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 864, 0, 0, "milliseconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "milliseconds", roundingMode: "floor" }),
|
||||
0, 0, 0, 0, -4, -17, -4, -865, 0, 0, "milliseconds");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "microseconds", roundingMode: "floor" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 864, 197, 0, "microseconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "microseconds", roundingMode: "floor" }),
|
||||
0, 0, 0, 0, -4, -17, -4, -864, -198, 0, "microseconds");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "nanoseconds", roundingMode: "floor" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "nanoseconds", roundingMode: "floor" }),
|
||||
0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds");
|
||||
const roundingMode = "floor";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
||||
|
@ -8,47 +8,31 @@ includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = Temporal.PlainTime.from("08:22:36.123456789");
|
||||
const later = Temporal.PlainTime.from("12:39:40.987654321");
|
||||
const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321);
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "hours", roundingMode: "halfExpand" }),
|
||||
0, 0, 0, 0, 4, 0, 0, 0, 0, 0, "hours");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "hours", roundingMode: "halfExpand" }),
|
||||
0, 0, 0, 0, -4, 0, 0, 0, 0, 0, "hours");
|
||||
const expected = [
|
||||
["hours", [0, 0, 0, 0, 4], [0, 0, 0, 0, -4]],
|
||||
["minutes", [0, 0, 0, 0, 4, 17], [0, 0, 0, 0, -4, -17]],
|
||||
["seconds", [0, 0, 0, 0, 4, 17, 5], [0, 0, 0, 0, -4, -17, -5]],
|
||||
["milliseconds", [0, 0, 0, 0, 4, 17, 4, 864], [0, 0, 0, 0, -4, -17, -4, -864]],
|
||||
["microseconds", [0, 0, 0, 0, 4, 17, 4, 864, 198], [0, 0, 0, 0, -4, -17, -4, -864, -198]],
|
||||
["nanoseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197, 532], [0, 0, 0, 0, -4, -17, -4, -864, -197, -532]],
|
||||
];
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "minutes", roundingMode: "halfExpand" }),
|
||||
0, 0, 0, 0, 4, 17, 0, 0, 0, 0, "minutes");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "minutes", roundingMode: "halfExpand" }),
|
||||
0, 0, 0, 0, -4, -17, 0, 0, 0, 0, "minutes");
|
||||
const roundingMode = "halfExpand";
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "seconds", roundingMode: "halfExpand" }),
|
||||
0, 0, 0, 0, 4, 17, 5, 0, 0, 0, "seconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "seconds", roundingMode: "halfExpand" }),
|
||||
0, 0, 0, 0, -4, -17, -5, 0, 0, 0, "seconds");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "milliseconds", roundingMode: "halfExpand" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 864, 0, 0, "milliseconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "milliseconds", roundingMode: "halfExpand" }),
|
||||
0, 0, 0, 0, -4, -17, -4, -864, 0, 0, "milliseconds");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "microseconds", roundingMode: "halfExpand" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 864, 198, 0, "microseconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "microseconds", roundingMode: "halfExpand" }),
|
||||
0, 0, 0, 0, -4, -17, -4, -864, -198, 0, "microseconds");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "nanoseconds", roundingMode: "halfExpand" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "nanoseconds", roundingMode: "halfExpand" }),
|
||||
0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds");
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
||||
|
@ -8,47 +8,31 @@ includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = Temporal.PlainTime.from("08:22:36.123456789");
|
||||
const later = Temporal.PlainTime.from("12:39:40.987654321");
|
||||
const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321);
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "hours", roundingMode: "trunc" }),
|
||||
0, 0, 0, 0, 4, 0, 0, 0, 0, 0, "hours");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "hours", roundingMode: "trunc" }),
|
||||
0, 0, 0, 0, -4, 0, 0, 0, 0, 0, "hours");
|
||||
const expected = [
|
||||
["hours", [0, 0, 0, 0, 4], [0, 0, 0, 0, -4]],
|
||||
["minutes", [0, 0, 0, 0, 4, 17], [0, 0, 0, 0, -4, -17]],
|
||||
["seconds", [0, 0, 0, 0, 4, 17, 4], [0, 0, 0, 0, -4, -17, -4]],
|
||||
["milliseconds", [0, 0, 0, 0, 4, 17, 4, 864], [0, 0, 0, 0, -4, -17, -4, -864]],
|
||||
["microseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197], [0, 0, 0, 0, -4, -17, -4, -864, -197]],
|
||||
["nanoseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197, 532], [0, 0, 0, 0, -4, -17, -4, -864, -197, -532]],
|
||||
];
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "minutes", roundingMode: "trunc" }),
|
||||
0, 0, 0, 0, 4, 17, 0, 0, 0, 0, "minutes");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "minutes", roundingMode: "trunc" }),
|
||||
0, 0, 0, 0, -4, -17, 0, 0, 0, 0, "minutes");
|
||||
const roundingMode = "trunc";
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "seconds", roundingMode: "trunc" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 0, 0, 0, "seconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "seconds", roundingMode: "trunc" }),
|
||||
0, 0, 0, 0, -4, -17, -4, 0, 0, 0, "seconds");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "milliseconds", roundingMode: "trunc" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 864, 0, 0, "milliseconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "milliseconds", roundingMode: "trunc" }),
|
||||
0, 0, 0, 0, -4, -17, -4, -864, 0, 0, "milliseconds");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "microseconds", roundingMode: "trunc" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 864, 197, 0, "microseconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "microseconds", roundingMode: "trunc" }),
|
||||
0, 0, 0, 0, -4, -17, -4, -864, -197, 0, "microseconds");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "nanoseconds", roundingMode: "trunc" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "nanoseconds", roundingMode: "trunc" }),
|
||||
0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds");
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
||||
|
@ -8,47 +8,31 @@ includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = Temporal.PlainTime.from("08:22:36.123456789");
|
||||
const later = Temporal.PlainTime.from("12:39:40.987654321");
|
||||
const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321);
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "hours", roundingMode: "ceil" }),
|
||||
0, 0, 0, 0, 5, 0, 0, 0, 0, 0, "hours");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "hours", roundingMode: "ceil" }),
|
||||
0, 0, 0, 0, -4, 0, 0, 0, 0, 0, "hours");
|
||||
const expected = [
|
||||
["hours", [0, 0, 0, 0, 5], [0, 0, 0, 0, -4]],
|
||||
["minutes", [0, 0, 0, 0, 4, 18], [0, 0, 0, 0, -4, -17]],
|
||||
["seconds", [0, 0, 0, 0, 4, 17, 5], [0, 0, 0, 0, -4, -17, -4]],
|
||||
["milliseconds", [0, 0, 0, 0, 4, 17, 4, 865], [0, 0, 0, 0, -4, -17, -4, -864]],
|
||||
["microseconds", [0, 0, 0, 0, 4, 17, 4, 864, 198], [0, 0, 0, 0, -4, -17, -4, -864, -197]],
|
||||
["nanoseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197, 532], [0, 0, 0, 0, -4, -17, -4, -864, -197, -532]],
|
||||
];
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "minutes", roundingMode: "ceil" }),
|
||||
0, 0, 0, 0, 4, 18, 0, 0, 0, 0, "minutes");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "minutes", roundingMode: "ceil" }),
|
||||
0, 0, 0, 0, -4, -17, 0, 0, 0, 0, "minutes");
|
||||
const roundingMode = "ceil";
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "seconds", roundingMode: "ceil" }),
|
||||
0, 0, 0, 0, 4, 17, 5, 0, 0, 0, "seconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "seconds", roundingMode: "ceil" }),
|
||||
0, 0, 0, 0, -4, -17, -4, 0, 0, 0, "seconds");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "milliseconds", roundingMode: "ceil" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 865, 0, 0, "milliseconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "milliseconds", roundingMode: "ceil" }),
|
||||
0, 0, 0, 0, -4, -17, -4, -864, 0, 0, "milliseconds");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "microseconds", roundingMode: "ceil" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 864, 198, 0, "microseconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "microseconds", roundingMode: "ceil" }),
|
||||
0, 0, 0, 0, -4, -17, -4, -864, -197, 0, "microseconds");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "nanoseconds", roundingMode: "ceil" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "nanoseconds", roundingMode: "ceil" }),
|
||||
0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds");
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
||||
|
@ -8,47 +8,31 @@ includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = Temporal.PlainTime.from("08:22:36.123456789");
|
||||
const later = Temporal.PlainTime.from("12:39:40.987654321");
|
||||
const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321);
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "hours", roundingMode: "floor" }),
|
||||
0, 0, 0, 0, 4, 0, 0, 0, 0, 0, "hours");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "hours", roundingMode: "floor" }),
|
||||
0, 0, 0, 0, -5, 0, 0, 0, 0, 0, "hours");
|
||||
const expected = [
|
||||
["hours", [0, 0, 0, 0, 4], [0, 0, 0, 0, -5]],
|
||||
["minutes", [0, 0, 0, 0, 4, 17], [0, 0, 0, 0, -4, -18]],
|
||||
["seconds", [0, 0, 0, 0, 4, 17, 4], [0, 0, 0, 0, -4, -17, -5]],
|
||||
["milliseconds", [0, 0, 0, 0, 4, 17, 4, 864], [0, 0, 0, 0, -4, -17, -4, -865]],
|
||||
["microseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197], [0, 0, 0, 0, -4, -17, -4, -864, -198]],
|
||||
["nanoseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197, 532], [0, 0, 0, 0, -4, -17, -4, -864, -197, -532]],
|
||||
];
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "minutes", roundingMode: "floor" }),
|
||||
0, 0, 0, 0, 4, 17, 0, 0, 0, 0, "minutes");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "minutes", roundingMode: "floor" }),
|
||||
0, 0, 0, 0, -4, -18, 0, 0, 0, 0, "minutes");
|
||||
const roundingMode = "floor";
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "seconds", roundingMode: "floor" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 0, 0, 0, "seconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "seconds", roundingMode: "floor" }),
|
||||
0, 0, 0, 0, -4, -17, -5, 0, 0, 0, "seconds");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "milliseconds", roundingMode: "floor" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 864, 0, 0, "milliseconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "milliseconds", roundingMode: "floor" }),
|
||||
0, 0, 0, 0, -4, -17, -4, -865, 0, 0, "milliseconds");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "microseconds", roundingMode: "floor" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 864, 197, 0, "microseconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "microseconds", roundingMode: "floor" }),
|
||||
0, 0, 0, 0, -4, -17, -4, -864, -198, 0, "microseconds");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "nanoseconds", roundingMode: "floor" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "nanoseconds", roundingMode: "floor" }),
|
||||
0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds");
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
||||
|
@ -8,47 +8,31 @@ includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = Temporal.PlainTime.from("08:22:36.123456789");
|
||||
const later = Temporal.PlainTime.from("12:39:40.987654321");
|
||||
const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321);
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "hours", roundingMode: "halfExpand" }),
|
||||
0, 0, 0, 0, 4, 0, 0, 0, 0, 0, "hours");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "hours", roundingMode: "halfExpand" }),
|
||||
0, 0, 0, 0, -4, 0, 0, 0, 0, 0, "hours");
|
||||
const expected = [
|
||||
["hours", [0, 0, 0, 0, 4], [0, 0, 0, 0, -4]],
|
||||
["minutes", [0, 0, 0, 0, 4, 17], [0, 0, 0, 0, -4, -17]],
|
||||
["seconds", [0, 0, 0, 0, 4, 17, 5], [0, 0, 0, 0, -4, -17, -5]],
|
||||
["milliseconds", [0, 0, 0, 0, 4, 17, 4, 864], [0, 0, 0, 0, -4, -17, -4, -864]],
|
||||
["microseconds", [0, 0, 0, 0, 4, 17, 4, 864, 198], [0, 0, 0, 0, -4, -17, -4, -864, -198]],
|
||||
["nanoseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197, 532], [0, 0, 0, 0, -4, -17, -4, -864, -197, -532]],
|
||||
];
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "minutes", roundingMode: "halfExpand" }),
|
||||
0, 0, 0, 0, 4, 17, 0, 0, 0, 0, "minutes");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "minutes", roundingMode: "halfExpand" }),
|
||||
0, 0, 0, 0, -4, -17, 0, 0, 0, 0, "minutes");
|
||||
const roundingMode = "halfExpand";
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "seconds", roundingMode: "halfExpand" }),
|
||||
0, 0, 0, 0, 4, 17, 5, 0, 0, 0, "seconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "seconds", roundingMode: "halfExpand" }),
|
||||
0, 0, 0, 0, -4, -17, -5, 0, 0, 0, "seconds");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "milliseconds", roundingMode: "halfExpand" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 864, 0, 0, "milliseconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "milliseconds", roundingMode: "halfExpand" }),
|
||||
0, 0, 0, 0, -4, -17, -4, -864, 0, 0, "milliseconds");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "microseconds", roundingMode: "halfExpand" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 864, 198, 0, "microseconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "microseconds", roundingMode: "halfExpand" }),
|
||||
0, 0, 0, 0, -4, -17, -4, -864, -198, 0, "microseconds");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "nanoseconds", roundingMode: "halfExpand" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "nanoseconds", roundingMode: "halfExpand" }),
|
||||
0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds");
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
||||
|
@ -8,47 +8,31 @@ includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = Temporal.PlainTime.from("08:22:36.123456789");
|
||||
const later = Temporal.PlainTime.from("12:39:40.987654321");
|
||||
const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321);
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "hours", roundingMode: "trunc" }),
|
||||
0, 0, 0, 0, 4, 0, 0, 0, 0, 0, "hours");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "hours", roundingMode: "trunc" }),
|
||||
0, 0, 0, 0, -4, 0, 0, 0, 0, 0, "hours");
|
||||
const expected = [
|
||||
["hours", [0, 0, 0, 0, 4], [0, 0, 0, 0, -4]],
|
||||
["minutes", [0, 0, 0, 0, 4, 17], [0, 0, 0, 0, -4, -17]],
|
||||
["seconds", [0, 0, 0, 0, 4, 17, 4], [0, 0, 0, 0, -4, -17, -4]],
|
||||
["milliseconds", [0, 0, 0, 0, 4, 17, 4, 864], [0, 0, 0, 0, -4, -17, -4, -864]],
|
||||
["microseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197], [0, 0, 0, 0, -4, -17, -4, -864, -197]],
|
||||
["nanoseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197, 532], [0, 0, 0, 0, -4, -17, -4, -864, -197, -532]],
|
||||
];
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "minutes", roundingMode: "trunc" }),
|
||||
0, 0, 0, 0, 4, 17, 0, 0, 0, 0, "minutes");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "minutes", roundingMode: "trunc" }),
|
||||
0, 0, 0, 0, -4, -17, 0, 0, 0, 0, "minutes");
|
||||
const roundingMode = "trunc";
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "seconds", roundingMode: "trunc" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 0, 0, 0, "seconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "seconds", roundingMode: "trunc" }),
|
||||
0, 0, 0, 0, -4, -17, -4, 0, 0, 0, "seconds");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "milliseconds", roundingMode: "trunc" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 864, 0, 0, "milliseconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "milliseconds", roundingMode: "trunc" }),
|
||||
0, 0, 0, 0, -4, -17, -4, -864, 0, 0, "milliseconds");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "microseconds", roundingMode: "trunc" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 864, 197, 0, "microseconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "microseconds", roundingMode: "trunc" }),
|
||||
0, 0, 0, 0, -4, -17, -4, -864, -197, 0, "microseconds");
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "nanoseconds", roundingMode: "trunc" }),
|
||||
0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "nanoseconds", roundingMode: "trunc" }),
|
||||
0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds");
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
||||
|
@ -8,19 +8,27 @@ includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = Temporal.PlainYearMonth.from("2019-01");
|
||||
const later = Temporal.PlainYearMonth.from("2021-09");
|
||||
const earlier = new Temporal.PlainYearMonth(2019, 1);
|
||||
const later = new Temporal.PlainYearMonth(2021, 9);
|
||||
|
||||
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");
|
||||
const expected = [
|
||||
["years", [3], [-2]],
|
||||
["months", [2, 8], [-2, -8]],
|
||||
];
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "months", roundingMode: "ceil" }),
|
||||
/* years = */ 2, /* months = */ 8, 0, 0, 0, 0, 0, 0, 0, 0, "months");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "months", roundingMode: "ceil" }),
|
||||
/* years = */ -2, /* months = */ -8, 0, 0, 0, 0, 0, 0, 0, 0, "months");
|
||||
const roundingMode = "ceil";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
||||
|
@ -8,19 +8,27 @@ includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = Temporal.PlainYearMonth.from("2019-01");
|
||||
const later = Temporal.PlainYearMonth.from("2021-09");
|
||||
const earlier = new Temporal.PlainYearMonth(2019, 1);
|
||||
const later = new Temporal.PlainYearMonth(2021, 9);
|
||||
|
||||
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");
|
||||
const expected = [
|
||||
["years", [2], [-3]],
|
||||
["months", [2, 8], [-2, -8]],
|
||||
];
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "months", roundingMode: "floor" }),
|
||||
/* years = */ 2, /* months = */ 8, 0, 0, 0, 0, 0, 0, 0, 0, "months");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "months", roundingMode: "floor" }),
|
||||
/* years = */ -2, /* months = */ -8, 0, 0, 0, 0, 0, 0, 0, 0, "months");
|
||||
const roundingMode = "floor";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
||||
|
@ -8,19 +8,27 @@ includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = Temporal.PlainYearMonth.from("2019-01");
|
||||
const later = Temporal.PlainYearMonth.from("2021-09");
|
||||
const earlier = new Temporal.PlainYearMonth(2019, 1);
|
||||
const later = new Temporal.PlainYearMonth(2021, 9);
|
||||
|
||||
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");
|
||||
const expected = [
|
||||
["years", [3], [-3]],
|
||||
["months", [2, 8], [-2, -8]],
|
||||
];
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "months", roundingMode: "halfExpand" }),
|
||||
/* years = */ 2, /* months = */ 8, 0, 0, 0, 0, 0, 0, 0, 0, "months");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "months", roundingMode: "halfExpand" }),
|
||||
/* years = */ -2, /* months = */ -8, 0, 0, 0, 0, 0, 0, 0, 0, "months");
|
||||
const roundingMode = "halfExpand";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
||||
|
@ -8,19 +8,27 @@ includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = Temporal.PlainYearMonth.from("2019-01");
|
||||
const later = Temporal.PlainYearMonth.from("2021-09");
|
||||
const earlier = new Temporal.PlainYearMonth(2019, 1);
|
||||
const later = new Temporal.PlainYearMonth(2021, 9);
|
||||
|
||||
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");
|
||||
const expected = [
|
||||
["years", [2], [-2]],
|
||||
["months", [2, 8], [-2, -8]],
|
||||
];
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit: "months", roundingMode: "trunc" }),
|
||||
/* years = */ 2, /* months = */ 8, 0, 0, 0, 0, 0, 0, 0, 0, "months");
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit: "months", roundingMode: "trunc" }),
|
||||
/* years = */ -2, /* months = */ -8, 0, 0, 0, 0, 0, 0, 0, 0, "months");
|
||||
const roundingMode = "trunc";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
||||
|
@ -8,19 +8,27 @@ includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = Temporal.PlainYearMonth.from("2019-01");
|
||||
const later = Temporal.PlainYearMonth.from("2021-09");
|
||||
const earlier = new Temporal.PlainYearMonth(2019, 1);
|
||||
const later = new Temporal.PlainYearMonth(2021, 9);
|
||||
|
||||
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");
|
||||
const expected = [
|
||||
["years", [3], [-2]],
|
||||
["months", [2, 8], [-2, -8]],
|
||||
];
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "months", roundingMode: "ceil" }),
|
||||
/* years = */ 2, /* months = */ 8, 0, 0, 0, 0, 0, 0, 0, 0, "months");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "months", roundingMode: "ceil" }),
|
||||
/* years = */ -2, /* months = */ -8, 0, 0, 0, 0, 0, 0, 0, 0, "months");
|
||||
const roundingMode = "ceil";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
||||
|
@ -8,19 +8,27 @@ includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = Temporal.PlainYearMonth.from("2019-01");
|
||||
const later = Temporal.PlainYearMonth.from("2021-09");
|
||||
const earlier = new Temporal.PlainYearMonth(2019, 1);
|
||||
const later = new Temporal.PlainYearMonth(2021, 9);
|
||||
|
||||
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");
|
||||
const expected = [
|
||||
["years", [2], [-3]],
|
||||
["months", [2, 8], [-2, -8]],
|
||||
];
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "months", roundingMode: "floor" }),
|
||||
/* years = */ 2, /* months = */ 8, 0, 0, 0, 0, 0, 0, 0, 0, "months");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "months", roundingMode: "floor" }),
|
||||
/* years = */ -2, /* months = */ -8, 0, 0, 0, 0, 0, 0, 0, 0, "months");
|
||||
const roundingMode = "floor";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
||||
|
@ -8,19 +8,27 @@ includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = Temporal.PlainYearMonth.from("2019-01");
|
||||
const later = Temporal.PlainYearMonth.from("2021-09");
|
||||
const earlier = new Temporal.PlainYearMonth(2019, 1);
|
||||
const later = new Temporal.PlainYearMonth(2021, 9);
|
||||
|
||||
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");
|
||||
const expected = [
|
||||
["years", [3], [-3]],
|
||||
["months", [2, 8], [-2, -8]],
|
||||
];
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "months", roundingMode: "halfExpand" }),
|
||||
/* years = */ 2, /* months = */ 8, 0, 0, 0, 0, 0, 0, 0, 0, "months");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "months", roundingMode: "halfExpand" }),
|
||||
/* years = */ -2, /* months = */ -8, 0, 0, 0, 0, 0, 0, 0, 0, "months");
|
||||
const roundingMode = "halfExpand";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
||||
|
@ -8,19 +8,27 @@ includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = Temporal.PlainYearMonth.from("2019-01");
|
||||
const later = Temporal.PlainYearMonth.from("2021-09");
|
||||
const earlier = new Temporal.PlainYearMonth(2019, 1);
|
||||
const later = new Temporal.PlainYearMonth(2021, 9);
|
||||
|
||||
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");
|
||||
const expected = [
|
||||
["years", [2], [-2]],
|
||||
["months", [2, 8], [-2, -8]],
|
||||
];
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit: "months", roundingMode: "trunc" }),
|
||||
/* years = */ 2, /* months = */ 8, 0, 0, 0, 0, 0, 0, 0, 0, "months");
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit: "months", roundingMode: "trunc" }),
|
||||
/* years = */ -2, /* months = */ -8, 0, 0, 0, 0, 0, 0, 0, 0, "months");
|
||||
const roundingMode = "trunc";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
||||
|
42
test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-ceil.js
vendored
Normal file
42
test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-ceil.js
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
// 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.zoneddatetime.prototype.since
|
||||
description: Tests calculations with roundingMode "ceil".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.ZonedDateTime(1546935756_123_456_789n, "UTC");
|
||||
const later = new Temporal.ZonedDateTime(1631018380_987_654_321n, "UTC");
|
||||
|
||||
const expected = [
|
||||
["years", [3], [-2]],
|
||||
["months", [0, 32], [0, -31]],
|
||||
["weeks", [0, 0, 140], [0, 0, -139]],
|
||||
["days", [0, 0, 0, 974], [0, 0, 0, -973]],
|
||||
["hours", [0, 0, 0, 0, 23357], [0, 0, 0, 0, -23356]],
|
||||
["minutes", [0, 0, 0, 0, 23356, 18], [0, 0, 0, 0, -23356, -17]],
|
||||
["seconds", [0, 0, 0, 0, 23356, 17, 5], [0, 0, 0, 0, -23356, -17, -4]],
|
||||
["milliseconds", [0, 0, 0, 0, 23356, 17, 4, 865], [0, 0, 0, 0, -23356, -17, -4, -864]],
|
||||
["microseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 198], [0, 0, 0, 0, -23356, -17, -4, -864, -197]],
|
||||
["nanoseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197, 532], [0, 0, 0, 0, -23356, -17, -4, -864, -197, -532]],
|
||||
];
|
||||
|
||||
const roundingMode = "ceil";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
42
test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-floor.js
vendored
Normal file
42
test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-floor.js
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
// 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.zoneddatetime.prototype.since
|
||||
description: Tests calculations with roundingMode "floor".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.ZonedDateTime(1546935756_123_456_789n, "UTC");
|
||||
const later = new Temporal.ZonedDateTime(1631018380_987_654_321n, "UTC");
|
||||
|
||||
const expected = [
|
||||
["years", [2], [-3]],
|
||||
["months", [0, 31], [0, -32]],
|
||||
["weeks", [0, 0, 139], [0, 0, -140]],
|
||||
["days", [0, 0, 0, 973], [0, 0, 0, -974]],
|
||||
["hours", [0, 0, 0, 0, 23356], [0, 0, 0, 0, -23357]],
|
||||
["minutes", [0, 0, 0, 0, 23356, 17], [0, 0, 0, 0, -23356, -18]],
|
||||
["seconds", [0, 0, 0, 0, 23356, 17, 4], [0, 0, 0, 0, -23356, -17, -5]],
|
||||
["milliseconds", [0, 0, 0, 0, 23356, 17, 4, 864], [0, 0, 0, 0, -23356, -17, -4, -865]],
|
||||
["microseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197], [0, 0, 0, 0, -23356, -17, -4, -864, -198]],
|
||||
["nanoseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197, 532], [0, 0, 0, 0, -23356, -17, -4, -864, -197, -532]],
|
||||
];
|
||||
|
||||
const roundingMode = "floor";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
42
test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-halfExpand.js
vendored
Normal file
42
test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-halfExpand.js
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
// 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.zoneddatetime.prototype.since
|
||||
description: Tests calculations with roundingMode "halfExpand".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.ZonedDateTime(1546935756_123_456_789n, "UTC");
|
||||
const later = new Temporal.ZonedDateTime(1631018380_987_654_321n, "UTC");
|
||||
|
||||
const expected = [
|
||||
["years", [3], [-3]],
|
||||
["months", [0, 32], [0, -32]],
|
||||
["weeks", [0, 0, 139], [0, 0, -139]],
|
||||
["days", [0, 0, 0, 973], [0, 0, 0, -973]],
|
||||
["hours", [0, 0, 0, 0, 23356], [0, 0, 0, 0, -23356]],
|
||||
["minutes", [0, 0, 0, 0, 23356, 17], [0, 0, 0, 0, -23356, -17]],
|
||||
["seconds", [0, 0, 0, 0, 23356, 17, 5], [0, 0, 0, 0, -23356, -17, -5]],
|
||||
["milliseconds", [0, 0, 0, 0, 23356, 17, 4, 864], [0, 0, 0, 0, -23356, -17, -4, -864]],
|
||||
["microseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 198], [0, 0, 0, 0, -23356, -17, -4, -864, -198]],
|
||||
["nanoseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197, 532], [0, 0, 0, 0, -23356, -17, -4, -864, -197, -532]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfExpand";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
42
test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-trunc.js
vendored
Normal file
42
test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-trunc.js
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
// 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.zoneddatetime.prototype.since
|
||||
description: Tests calculations with roundingMode "trunc".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.ZonedDateTime(1546935756_123_456_789n, "UTC");
|
||||
const later = new Temporal.ZonedDateTime(1631018380_987_654_321n, "UTC");
|
||||
|
||||
const expected = [
|
||||
["years", [2], [-2]],
|
||||
["months", [0, 31], [0, -31]],
|
||||
["weeks", [0, 0, 139], [0, 0, -139]],
|
||||
["days", [0, 0, 0, 973], [0, 0, 0, -973]],
|
||||
["hours", [0, 0, 0, 0, 23356], [0, 0, 0, 0, -23356]],
|
||||
["minutes", [0, 0, 0, 0, 23356, 17], [0, 0, 0, 0, -23356, -17]],
|
||||
["seconds", [0, 0, 0, 0, 23356, 17, 4], [0, 0, 0, 0, -23356, -17, -4]],
|
||||
["milliseconds", [0, 0, 0, 0, 23356, 17, 4, 864], [0, 0, 0, 0, -23356, -17, -4, -864]],
|
||||
["microseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197], [0, 0, 0, 0, -23356, -17, -4, -864, -197]],
|
||||
["nanoseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197, 532], [0, 0, 0, 0, -23356, -17, -4, -864, -197, -532]],
|
||||
];
|
||||
|
||||
const roundingMode = "trunc";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
later.since(earlier, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.since(later, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
42
test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-ceil.js
vendored
Normal file
42
test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-ceil.js
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
// 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.zoneddatetime.prototype.until
|
||||
description: Tests calculations with roundingMode "ceil".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.ZonedDateTime(1546935756_123_456_789n, "UTC");
|
||||
const later = new Temporal.ZonedDateTime(1631018380_987_654_321n, "UTC");
|
||||
|
||||
const expected = [
|
||||
["years", [3], [-2]],
|
||||
["months", [0, 32], [0, -31]],
|
||||
["weeks", [0, 0, 140], [0, 0, -139]],
|
||||
["days", [0, 0, 0, 974], [0, 0, 0, -973]],
|
||||
["hours", [0, 0, 0, 0, 23357], [0, 0, 0, 0, -23356]],
|
||||
["minutes", [0, 0, 0, 0, 23356, 18], [0, 0, 0, 0, -23356, -17]],
|
||||
["seconds", [0, 0, 0, 0, 23356, 17, 5], [0, 0, 0, 0, -23356, -17, -4]],
|
||||
["milliseconds", [0, 0, 0, 0, 23356, 17, 4, 865], [0, 0, 0, 0, -23356, -17, -4, -864]],
|
||||
["microseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 198], [0, 0, 0, 0, -23356, -17, -4, -864, -197]],
|
||||
["nanoseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197, 532], [0, 0, 0, 0, -23356, -17, -4, -864, -197, -532]],
|
||||
];
|
||||
|
||||
const roundingMode = "ceil";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
42
test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-floor.js
vendored
Normal file
42
test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-floor.js
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
// 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.zoneddatetime.prototype.until
|
||||
description: Tests calculations with roundingMode "floor".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.ZonedDateTime(1546935756_123_456_789n, "UTC");
|
||||
const later = new Temporal.ZonedDateTime(1631018380_987_654_321n, "UTC");
|
||||
|
||||
const expected = [
|
||||
["years", [2], [-3]],
|
||||
["months", [0, 31], [0, -32]],
|
||||
["weeks", [0, 0, 139], [0, 0, -140]],
|
||||
["days", [0, 0, 0, 973], [0, 0, 0, -974]],
|
||||
["hours", [0, 0, 0, 0, 23356], [0, 0, 0, 0, -23357]],
|
||||
["minutes", [0, 0, 0, 0, 23356, 17], [0, 0, 0, 0, -23356, -18]],
|
||||
["seconds", [0, 0, 0, 0, 23356, 17, 4], [0, 0, 0, 0, -23356, -17, -5]],
|
||||
["milliseconds", [0, 0, 0, 0, 23356, 17, 4, 864], [0, 0, 0, 0, -23356, -17, -4, -865]],
|
||||
["microseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197], [0, 0, 0, 0, -23356, -17, -4, -864, -198]],
|
||||
["nanoseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197, 532], [0, 0, 0, 0, -23356, -17, -4, -864, -197, -532]],
|
||||
];
|
||||
|
||||
const roundingMode = "floor";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
42
test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-halfExpand.js
vendored
Normal file
42
test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-halfExpand.js
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
// 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.zoneddatetime.prototype.until
|
||||
description: Tests calculations with roundingMode "halfExpand".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.ZonedDateTime(1546935756_123_456_789n, "UTC");
|
||||
const later = new Temporal.ZonedDateTime(1631018380_987_654_321n, "UTC");
|
||||
|
||||
const expected = [
|
||||
["years", [3], [-3]],
|
||||
["months", [0, 32], [0, -32]],
|
||||
["weeks", [0, 0, 139], [0, 0, -139]],
|
||||
["days", [0, 0, 0, 973], [0, 0, 0, -973]],
|
||||
["hours", [0, 0, 0, 0, 23356], [0, 0, 0, 0, -23356]],
|
||||
["minutes", [0, 0, 0, 0, 23356, 17], [0, 0, 0, 0, -23356, -17]],
|
||||
["seconds", [0, 0, 0, 0, 23356, 17, 5], [0, 0, 0, 0, -23356, -17, -5]],
|
||||
["milliseconds", [0, 0, 0, 0, 23356, 17, 4, 864], [0, 0, 0, 0, -23356, -17, -4, -864]],
|
||||
["microseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 198], [0, 0, 0, 0, -23356, -17, -4, -864, -198]],
|
||||
["nanoseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197, 532], [0, 0, 0, 0, -23356, -17, -4, -864, -197, -532]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfExpand";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
42
test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-trunc.js
vendored
Normal file
42
test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-trunc.js
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
// 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.zoneddatetime.prototype.until
|
||||
description: Tests calculations with roundingMode "trunc".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.ZonedDateTime(1546935756_123_456_789n, "UTC");
|
||||
const later = new Temporal.ZonedDateTime(1631018380_987_654_321n, "UTC");
|
||||
|
||||
const expected = [
|
||||
["years", [2], [-2]],
|
||||
["months", [0, 31], [0, -31]],
|
||||
["weeks", [0, 0, 139], [0, 0, -139]],
|
||||
["days", [0, 0, 0, 973], [0, 0, 0, -973]],
|
||||
["hours", [0, 0, 0, 0, 23356], [0, 0, 0, 0, -23356]],
|
||||
["minutes", [0, 0, 0, 0, 23356, 17], [0, 0, 0, 0, -23356, -17]],
|
||||
["seconds", [0, 0, 0, 0, 23356, 17, 4], [0, 0, 0, 0, -23356, -17, -4]],
|
||||
["milliseconds", [0, 0, 0, 0, 23356, 17, 4, 864], [0, 0, 0, 0, -23356, -17, -4, -864]],
|
||||
["microseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197], [0, 0, 0, 0, -23356, -17, -4, -864, -197]],
|
||||
["nanoseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197, 532], [0, 0, 0, 0, -23356, -17, -4, -864, -197, -532]],
|
||||
];
|
||||
|
||||
const roundingMode = "trunc";
|
||||
|
||||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||
TemporalHelpers.assertDuration(
|
||||
earlier.until(later, { smallestUnit, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
later.until(earlier, { smallestUnit, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
@ -56,182 +56,6 @@ assert.sameValue(`${ later.since(earlier, {
|
||||
}) }`, "PT22586123M");
|
||||
var largestUnit = "hours";
|
||||
|
||||
// halfExpand
|
||||
var roundingMode = "halfExpand";
|
||||
var incrementOneNearest = [
|
||||
[
|
||||
"hours",
|
||||
"PT376435H"
|
||||
],
|
||||
[
|
||||
"minutes",
|
||||
"PT376435H23M"
|
||||
],
|
||||
[
|
||||
"seconds",
|
||||
"PT376435H23M8S"
|
||||
],
|
||||
[
|
||||
"milliseconds",
|
||||
"PT376435H23M8.149S"
|
||||
],
|
||||
[
|
||||
"microseconds",
|
||||
"PT376435H23M8.148529S"
|
||||
],
|
||||
[
|
||||
"nanoseconds",
|
||||
"PT376435H23M8.148529313S"
|
||||
]
|
||||
];
|
||||
incrementOneNearest.forEach(([smallestUnit, expected]) => {
|
||||
assert.sameValue(`${ later.since(earlier, {
|
||||
largestUnit,
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, expected);
|
||||
assert.sameValue(`${ earlier.since(later, {
|
||||
largestUnit,
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, `-${ expected }`);
|
||||
});
|
||||
|
||||
// ceil
|
||||
var roundingMode = "ceil";
|
||||
var incrementOneCeil = [
|
||||
[
|
||||
"hours",
|
||||
"PT376436H",
|
||||
"-PT376435H"
|
||||
],
|
||||
[
|
||||
"minutes",
|
||||
"PT376435H24M",
|
||||
"-PT376435H23M"
|
||||
],
|
||||
[
|
||||
"seconds",
|
||||
"PT376435H23M9S",
|
||||
"-PT376435H23M8S"
|
||||
],
|
||||
[
|
||||
"milliseconds",
|
||||
"PT376435H23M8.149S",
|
||||
"-PT376435H23M8.148S"
|
||||
],
|
||||
[
|
||||
"microseconds",
|
||||
"PT376435H23M8.14853S",
|
||||
"-PT376435H23M8.148529S"
|
||||
],
|
||||
[
|
||||
"nanoseconds",
|
||||
"PT376435H23M8.148529313S",
|
||||
"-PT376435H23M8.148529313S"
|
||||
]
|
||||
];
|
||||
incrementOneCeil.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
assert.sameValue(`${ later.since(earlier, {
|
||||
largestUnit,
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, expectedPositive);
|
||||
assert.sameValue(`${ earlier.since(later, {
|
||||
largestUnit,
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, expectedNegative);
|
||||
});
|
||||
|
||||
// floor
|
||||
var roundingMode = "floor";
|
||||
var incrementOneFloor = [
|
||||
[
|
||||
"hours",
|
||||
"PT376435H",
|
||||
"-PT376436H"
|
||||
],
|
||||
[
|
||||
"minutes",
|
||||
"PT376435H23M",
|
||||
"-PT376435H24M"
|
||||
],
|
||||
[
|
||||
"seconds",
|
||||
"PT376435H23M8S",
|
||||
"-PT376435H23M9S"
|
||||
],
|
||||
[
|
||||
"milliseconds",
|
||||
"PT376435H23M8.148S",
|
||||
"-PT376435H23M8.149S"
|
||||
],
|
||||
[
|
||||
"microseconds",
|
||||
"PT376435H23M8.148529S",
|
||||
"-PT376435H23M8.14853S"
|
||||
],
|
||||
[
|
||||
"nanoseconds",
|
||||
"PT376435H23M8.148529313S",
|
||||
"-PT376435H23M8.148529313S"
|
||||
]
|
||||
];
|
||||
incrementOneFloor.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
assert.sameValue(`${ later.since(earlier, {
|
||||
largestUnit,
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, expectedPositive);
|
||||
assert.sameValue(`${ earlier.since(later, {
|
||||
largestUnit,
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, expectedNegative);
|
||||
});
|
||||
|
||||
// trunc
|
||||
var roundingMode = "trunc";
|
||||
var incrementOneTrunc = [
|
||||
[
|
||||
"hours",
|
||||
"PT376435H"
|
||||
],
|
||||
[
|
||||
"minutes",
|
||||
"PT376435H23M"
|
||||
],
|
||||
[
|
||||
"seconds",
|
||||
"PT376435H23M8S"
|
||||
],
|
||||
[
|
||||
"milliseconds",
|
||||
"PT376435H23M8.148S"
|
||||
],
|
||||
[
|
||||
"microseconds",
|
||||
"PT376435H23M8.148529S"
|
||||
],
|
||||
[
|
||||
"nanoseconds",
|
||||
"PT376435H23M8.148529313S"
|
||||
]
|
||||
];
|
||||
incrementOneTrunc.forEach(([smallestUnit, expected]) => {
|
||||
assert.sameValue(`${ later.since(earlier, {
|
||||
largestUnit,
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, expected);
|
||||
assert.sameValue(`${ earlier.since(later, {
|
||||
largestUnit,
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, `-${ expected }`);
|
||||
});
|
||||
|
||||
// rounds to an increment of hours
|
||||
assert.sameValue(`${ later.since(earlier, {
|
||||
largestUnit,
|
||||
|
@ -56,182 +56,6 @@ assert.sameValue(`${ earlier.until(later, {
|
||||
}) }`, "PT26436596M");
|
||||
var largestUnit = "hours";
|
||||
|
||||
// halfExpand
|
||||
var roundingMode = "halfExpand";
|
||||
var incrementOneNearest = [
|
||||
[
|
||||
"hours",
|
||||
"PT440610H"
|
||||
],
|
||||
[
|
||||
"minutes",
|
||||
"PT440609H56M"
|
||||
],
|
||||
[
|
||||
"seconds",
|
||||
"PT440609H56M3S"
|
||||
],
|
||||
[
|
||||
"milliseconds",
|
||||
"PT440609H56M3.149S"
|
||||
],
|
||||
[
|
||||
"microseconds",
|
||||
"PT440609H56M3.148529S"
|
||||
],
|
||||
[
|
||||
"nanoseconds",
|
||||
"PT440609H56M3.148529313S"
|
||||
]
|
||||
];
|
||||
incrementOneNearest.forEach(([smallestUnit, expected]) => {
|
||||
assert.sameValue(`${ earlier.until(later, {
|
||||
largestUnit,
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, expected);
|
||||
assert.sameValue(`${ later.until(earlier, {
|
||||
largestUnit,
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, `-${ expected }`);
|
||||
});
|
||||
|
||||
// ceil
|
||||
var roundingMode = "ceil";
|
||||
var incrementOneCeil = [
|
||||
[
|
||||
"hours",
|
||||
"PT440610H",
|
||||
"-PT440609H"
|
||||
],
|
||||
[
|
||||
"minutes",
|
||||
"PT440609H57M",
|
||||
"-PT440609H56M"
|
||||
],
|
||||
[
|
||||
"seconds",
|
||||
"PT440609H56M4S",
|
||||
"-PT440609H56M3S"
|
||||
],
|
||||
[
|
||||
"milliseconds",
|
||||
"PT440609H56M3.149S",
|
||||
"-PT440609H56M3.148S"
|
||||
],
|
||||
[
|
||||
"microseconds",
|
||||
"PT440609H56M3.14853S",
|
||||
"-PT440609H56M3.148529S"
|
||||
],
|
||||
[
|
||||
"nanoseconds",
|
||||
"PT440609H56M3.148529313S",
|
||||
"-PT440609H56M3.148529313S"
|
||||
]
|
||||
];
|
||||
incrementOneCeil.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
assert.sameValue(`${ earlier.until(later, {
|
||||
largestUnit,
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, expectedPositive);
|
||||
assert.sameValue(`${ later.until(earlier, {
|
||||
largestUnit,
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, expectedNegative);
|
||||
});
|
||||
|
||||
// floor
|
||||
var roundingMode = "floor";
|
||||
var incrementOneFloor = [
|
||||
[
|
||||
"hours",
|
||||
"PT440609H",
|
||||
"-PT440610H"
|
||||
],
|
||||
[
|
||||
"minutes",
|
||||
"PT440609H56M",
|
||||
"-PT440609H57M"
|
||||
],
|
||||
[
|
||||
"seconds",
|
||||
"PT440609H56M3S",
|
||||
"-PT440609H56M4S"
|
||||
],
|
||||
[
|
||||
"milliseconds",
|
||||
"PT440609H56M3.148S",
|
||||
"-PT440609H56M3.149S"
|
||||
],
|
||||
[
|
||||
"microseconds",
|
||||
"PT440609H56M3.148529S",
|
||||
"-PT440609H56M3.14853S"
|
||||
],
|
||||
[
|
||||
"nanoseconds",
|
||||
"PT440609H56M3.148529313S",
|
||||
"-PT440609H56M3.148529313S"
|
||||
]
|
||||
];
|
||||
incrementOneFloor.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
assert.sameValue(`${ earlier.until(later, {
|
||||
largestUnit,
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, expectedPositive);
|
||||
assert.sameValue(`${ later.until(earlier, {
|
||||
largestUnit,
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, expectedNegative);
|
||||
});
|
||||
|
||||
// trunc
|
||||
var roundingMode = "trunc";
|
||||
var incrementOneTrunc = [
|
||||
[
|
||||
"hours",
|
||||
"PT440609H"
|
||||
],
|
||||
[
|
||||
"minutes",
|
||||
"PT440609H56M"
|
||||
],
|
||||
[
|
||||
"seconds",
|
||||
"PT440609H56M3S"
|
||||
],
|
||||
[
|
||||
"milliseconds",
|
||||
"PT440609H56M3.148S"
|
||||
],
|
||||
[
|
||||
"microseconds",
|
||||
"PT440609H56M3.148529S"
|
||||
],
|
||||
[
|
||||
"nanoseconds",
|
||||
"PT440609H56M3.148529313S"
|
||||
]
|
||||
];
|
||||
incrementOneTrunc.forEach(([smallestUnit, expected]) => {
|
||||
assert.sameValue(`${ earlier.until(later, {
|
||||
largestUnit,
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, expected);
|
||||
assert.sameValue(`${ later.until(earlier, {
|
||||
largestUnit,
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, `-${ expected }`);
|
||||
});
|
||||
|
||||
// rounds to an increment of hours
|
||||
assert.sameValue(`${ earlier.until(later, {
|
||||
largestUnit,
|
||||
|
@ -105,238 +105,6 @@ assert.sameValue(`${ later.since(earlier, {
|
||||
smallestUnit: "weeks",
|
||||
roundingMode: "halfExpand"
|
||||
}) }`, "P139W");
|
||||
var incrementOneNearest = [
|
||||
[
|
||||
"years",
|
||||
"P3Y"
|
||||
],
|
||||
[
|
||||
"months",
|
||||
"P32M"
|
||||
],
|
||||
[
|
||||
"weeks",
|
||||
"P139W"
|
||||
],
|
||||
[
|
||||
"days",
|
||||
"P973D"
|
||||
],
|
||||
[
|
||||
"hours",
|
||||
"PT23356H"
|
||||
],
|
||||
[
|
||||
"minutes",
|
||||
"PT23356H17M"
|
||||
],
|
||||
[
|
||||
"seconds",
|
||||
"PT23356H17M5S"
|
||||
],
|
||||
[
|
||||
"milliseconds",
|
||||
"PT23356H17M4.864S"
|
||||
],
|
||||
[
|
||||
"microseconds",
|
||||
"PT23356H17M4.864198S"
|
||||
],
|
||||
[
|
||||
"nanoseconds",
|
||||
"PT23356H17M4.864197532S"
|
||||
]
|
||||
];
|
||||
incrementOneNearest.forEach(([smallestUnit, expected]) => {
|
||||
var roundingMode = "halfExpand";
|
||||
assert.sameValue(`${ later.since(earlier, {
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, expected);
|
||||
assert.sameValue(`${ earlier.since(later, {
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, `-${ expected }`);
|
||||
});
|
||||
var incrementOneCeil = [
|
||||
[
|
||||
"years",
|
||||
"P3Y",
|
||||
"-P2Y"
|
||||
],
|
||||
[
|
||||
"months",
|
||||
"P32M",
|
||||
"-P31M"
|
||||
],
|
||||
[
|
||||
"weeks",
|
||||
"P140W",
|
||||
"-P139W"
|
||||
],
|
||||
[
|
||||
"days",
|
||||
"P974D",
|
||||
"-P973D"
|
||||
],
|
||||
[
|
||||
"hours",
|
||||
"PT23357H",
|
||||
"-PT23356H"
|
||||
],
|
||||
[
|
||||
"minutes",
|
||||
"PT23356H18M",
|
||||
"-PT23356H17M"
|
||||
],
|
||||
[
|
||||
"seconds",
|
||||
"PT23356H17M5S",
|
||||
"-PT23356H17M4S"
|
||||
],
|
||||
[
|
||||
"milliseconds",
|
||||
"PT23356H17M4.865S",
|
||||
"-PT23356H17M4.864S"
|
||||
],
|
||||
[
|
||||
"microseconds",
|
||||
"PT23356H17M4.864198S",
|
||||
"-PT23356H17M4.864197S"
|
||||
],
|
||||
[
|
||||
"nanoseconds",
|
||||
"PT23356H17M4.864197532S",
|
||||
"-PT23356H17M4.864197532S"
|
||||
]
|
||||
];
|
||||
incrementOneCeil.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
var roundingMode = "ceil";
|
||||
assert.sameValue(`${ later.since(earlier, {
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, expectedPositive);
|
||||
assert.sameValue(`${ earlier.since(later, {
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, expectedNegative);
|
||||
});
|
||||
var incrementOneFloor = [
|
||||
[
|
||||
"years",
|
||||
"P2Y",
|
||||
"-P3Y"
|
||||
],
|
||||
[
|
||||
"months",
|
||||
"P31M",
|
||||
"-P32M"
|
||||
],
|
||||
[
|
||||
"weeks",
|
||||
"P139W",
|
||||
"-P140W"
|
||||
],
|
||||
[
|
||||
"days",
|
||||
"P973D",
|
||||
"-P974D"
|
||||
],
|
||||
[
|
||||
"hours",
|
||||
"PT23356H",
|
||||
"-PT23357H"
|
||||
],
|
||||
[
|
||||
"minutes",
|
||||
"PT23356H17M",
|
||||
"-PT23356H18M"
|
||||
],
|
||||
[
|
||||
"seconds",
|
||||
"PT23356H17M4S",
|
||||
"-PT23356H17M5S"
|
||||
],
|
||||
[
|
||||
"milliseconds",
|
||||
"PT23356H17M4.864S",
|
||||
"-PT23356H17M4.865S"
|
||||
],
|
||||
[
|
||||
"microseconds",
|
||||
"PT23356H17M4.864197S",
|
||||
"-PT23356H17M4.864198S"
|
||||
],
|
||||
[
|
||||
"nanoseconds",
|
||||
"PT23356H17M4.864197532S",
|
||||
"-PT23356H17M4.864197532S"
|
||||
]
|
||||
];
|
||||
incrementOneFloor.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
var roundingMode = "floor";
|
||||
assert.sameValue(`${ later.since(earlier, {
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, expectedPositive);
|
||||
assert.sameValue(`${ earlier.since(later, {
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, expectedNegative);
|
||||
});
|
||||
var incrementOneTrunc = [
|
||||
[
|
||||
"years",
|
||||
"P2Y"
|
||||
],
|
||||
[
|
||||
"months",
|
||||
"P31M"
|
||||
],
|
||||
[
|
||||
"weeks",
|
||||
"P139W"
|
||||
],
|
||||
[
|
||||
"days",
|
||||
"P973D"
|
||||
],
|
||||
[
|
||||
"hours",
|
||||
"PT23356H"
|
||||
],
|
||||
[
|
||||
"minutes",
|
||||
"PT23356H17M"
|
||||
],
|
||||
[
|
||||
"seconds",
|
||||
"PT23356H17M4S"
|
||||
],
|
||||
[
|
||||
"milliseconds",
|
||||
"PT23356H17M4.864S"
|
||||
],
|
||||
[
|
||||
"microseconds",
|
||||
"PT23356H17M4.864197S"
|
||||
],
|
||||
[
|
||||
"nanoseconds",
|
||||
"PT23356H17M4.864197532S"
|
||||
]
|
||||
];
|
||||
incrementOneTrunc.forEach(([smallestUnit, expected]) => {
|
||||
var roundingMode = "trunc";
|
||||
assert.sameValue(`${ later.since(earlier, {
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, expected);
|
||||
assert.sameValue(`${ earlier.since(later, {
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, `-${ expected }`);
|
||||
});
|
||||
|
||||
// rounds to an increment of hours
|
||||
assert.sameValue(`${ later.since(earlier, {
|
||||
|
@ -109,238 +109,6 @@ assert.sameValue(`${ earlier.until(later, {
|
||||
smallestUnit: "days",
|
||||
roundingMode: "halfExpand"
|
||||
}) }`, "P973D");
|
||||
var incrementOneNearest = [
|
||||
[
|
||||
"years",
|
||||
"P3Y"
|
||||
],
|
||||
[
|
||||
"months",
|
||||
"P32M"
|
||||
],
|
||||
[
|
||||
"weeks",
|
||||
"P139W"
|
||||
],
|
||||
[
|
||||
"days",
|
||||
"P973D"
|
||||
],
|
||||
[
|
||||
"hours",
|
||||
"PT23356H"
|
||||
],
|
||||
[
|
||||
"minutes",
|
||||
"PT23356H17M"
|
||||
],
|
||||
[
|
||||
"seconds",
|
||||
"PT23356H17M5S"
|
||||
],
|
||||
[
|
||||
"milliseconds",
|
||||
"PT23356H17M4.864S"
|
||||
],
|
||||
[
|
||||
"microseconds",
|
||||
"PT23356H17M4.864198S"
|
||||
],
|
||||
[
|
||||
"nanoseconds",
|
||||
"PT23356H17M4.864197532S"
|
||||
]
|
||||
];
|
||||
incrementOneNearest.forEach(([smallestUnit, expected]) => {
|
||||
var roundingMode = "halfExpand";
|
||||
assert.sameValue(`${ earlier.until(later, {
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, expected);
|
||||
assert.sameValue(`${ later.until(earlier, {
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, `-${ expected }`);
|
||||
});
|
||||
var incrementOneCeil = [
|
||||
[
|
||||
"years",
|
||||
"P3Y",
|
||||
"-P2Y"
|
||||
],
|
||||
[
|
||||
"months",
|
||||
"P32M",
|
||||
"-P31M"
|
||||
],
|
||||
[
|
||||
"weeks",
|
||||
"P140W",
|
||||
"-P139W"
|
||||
],
|
||||
[
|
||||
"days",
|
||||
"P974D",
|
||||
"-P973D"
|
||||
],
|
||||
[
|
||||
"hours",
|
||||
"PT23357H",
|
||||
"-PT23356H"
|
||||
],
|
||||
[
|
||||
"minutes",
|
||||
"PT23356H18M",
|
||||
"-PT23356H17M"
|
||||
],
|
||||
[
|
||||
"seconds",
|
||||
"PT23356H17M5S",
|
||||
"-PT23356H17M4S"
|
||||
],
|
||||
[
|
||||
"milliseconds",
|
||||
"PT23356H17M4.865S",
|
||||
"-PT23356H17M4.864S"
|
||||
],
|
||||
[
|
||||
"microseconds",
|
||||
"PT23356H17M4.864198S",
|
||||
"-PT23356H17M4.864197S"
|
||||
],
|
||||
[
|
||||
"nanoseconds",
|
||||
"PT23356H17M4.864197532S",
|
||||
"-PT23356H17M4.864197532S"
|
||||
]
|
||||
];
|
||||
incrementOneCeil.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
var roundingMode = "ceil";
|
||||
assert.sameValue(`${ earlier.until(later, {
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, expectedPositive);
|
||||
assert.sameValue(`${ later.until(earlier, {
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, expectedNegative);
|
||||
});
|
||||
var incrementOneFloor = [
|
||||
[
|
||||
"years",
|
||||
"P2Y",
|
||||
"-P3Y"
|
||||
],
|
||||
[
|
||||
"months",
|
||||
"P31M",
|
||||
"-P32M"
|
||||
],
|
||||
[
|
||||
"weeks",
|
||||
"P139W",
|
||||
"-P140W"
|
||||
],
|
||||
[
|
||||
"days",
|
||||
"P973D",
|
||||
"-P974D"
|
||||
],
|
||||
[
|
||||
"hours",
|
||||
"PT23356H",
|
||||
"-PT23357H"
|
||||
],
|
||||
[
|
||||
"minutes",
|
||||
"PT23356H17M",
|
||||
"-PT23356H18M"
|
||||
],
|
||||
[
|
||||
"seconds",
|
||||
"PT23356H17M4S",
|
||||
"-PT23356H17M5S"
|
||||
],
|
||||
[
|
||||
"milliseconds",
|
||||
"PT23356H17M4.864S",
|
||||
"-PT23356H17M4.865S"
|
||||
],
|
||||
[
|
||||
"microseconds",
|
||||
"PT23356H17M4.864197S",
|
||||
"-PT23356H17M4.864198S"
|
||||
],
|
||||
[
|
||||
"nanoseconds",
|
||||
"PT23356H17M4.864197532S",
|
||||
"-PT23356H17M4.864197532S"
|
||||
]
|
||||
];
|
||||
incrementOneFloor.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
||||
var roundingMode = "floor";
|
||||
assert.sameValue(`${ earlier.until(later, {
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, expectedPositive);
|
||||
assert.sameValue(`${ later.until(earlier, {
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, expectedNegative);
|
||||
});
|
||||
var incrementOneTrunc = [
|
||||
[
|
||||
"years",
|
||||
"P2Y"
|
||||
],
|
||||
[
|
||||
"months",
|
||||
"P31M"
|
||||
],
|
||||
[
|
||||
"weeks",
|
||||
"P139W"
|
||||
],
|
||||
[
|
||||
"days",
|
||||
"P973D"
|
||||
],
|
||||
[
|
||||
"hours",
|
||||
"PT23356H"
|
||||
],
|
||||
[
|
||||
"minutes",
|
||||
"PT23356H17M"
|
||||
],
|
||||
[
|
||||
"seconds",
|
||||
"PT23356H17M4S"
|
||||
],
|
||||
[
|
||||
"milliseconds",
|
||||
"PT23356H17M4.864S"
|
||||
],
|
||||
[
|
||||
"microseconds",
|
||||
"PT23356H17M4.864197S"
|
||||
],
|
||||
[
|
||||
"nanoseconds",
|
||||
"PT23356H17M4.864197532S"
|
||||
]
|
||||
];
|
||||
incrementOneTrunc.forEach(([smallestUnit, expected]) => {
|
||||
var roundingMode = "trunc";
|
||||
assert.sameValue(`${ earlier.until(later, {
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, expected);
|
||||
assert.sameValue(`${ later.until(earlier, {
|
||||
smallestUnit,
|
||||
roundingMode
|
||||
}) }`, `-${ expected }`);
|
||||
});
|
||||
|
||||
// rounds to an increment of hours
|
||||
assert.sameValue(`${ earlier.until(later, {
|
||||
|
Loading…
x
Reference in New Issue
Block a user