mirror of
https://github.com/tc39/test262.git
synced 2025-07-20 12:34:41 +02:00
Temporal: Add tests for new rounding modes
See https://github.com/tc39/proposal-temporal/pull/2262 which added new rounding modes from NumberFormat V3. These tests use the same format as the previous ones. The tests for the "half" rounding modes aren't very good yet, as they don't show any of the differences between the tiebreaking schemes; there aren't any ties in the data to be broken. (Except in .toString().) A subsequent commit will correct this.
This commit is contained in:
parent
4155842c37
commit
c84e5701cd
42
test/built-ins/Temporal/Duration/prototype/round/roundingmode-expand.js
vendored
Normal file
42
test/built-ins/Temporal/Duration/prototype/round/roundingmode-expand.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.duration.prototype.round
|
||||
description: Tests calculations with roundingMode "expand".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 500, 987);
|
||||
const relativeTo = new Temporal.PlainDate(2020, 1, 1);
|
||||
|
||||
const expected = [
|
||||
["years", [6], [-6]],
|
||||
["months", [5, 8], [-5, -8]],
|
||||
["weeks", [5, 6, 9], [-5, -6, -9]],
|
||||
["days", [5, 6, 7, 10], [-5, -6, -7, -10]],
|
||||
["hours", [5, 6, 7, 9, 17], [-5, -6, -7, -9, -17]],
|
||||
["minutes", [5, 6, 7, 9, 16, 31], [-5, -6, -7, -9, -16, -31]],
|
||||
["seconds", [5, 6, 7, 9, 16, 30, 21], [-5, -6, -7, -9, -16, -30, -21]],
|
||||
["milliseconds", [5, 6, 7, 9, 16, 30, 20, 124], [-5, -6, -7, -9, -16, -30, -20, -124]],
|
||||
["microseconds", [5, 6, 7, 9, 16, 30, 20, 123, 501], [-5, -6, -7, -9, -16, -30, -20, -123, -501]],
|
||||
["nanoseconds", [5, 6, 7, 9, 16, 30, 20, 123, 500, 987], [-5, -6, -7, -9, -16, -30, -20, -123, -500, -987]],
|
||||
];
|
||||
|
||||
const roundingMode = "expand";
|
||||
|
||||
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(
|
||||
instance.round({ smallestUnit, relativeTo, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
instance.negated().round({ smallestUnit, relativeTo, 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/Duration/prototype/round/roundingmode-halfCeil.js
vendored
Normal file
42
test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfCeil.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.duration.prototype.round
|
||||
description: Tests calculations with roundingMode "halfCeil".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 500, 987);
|
||||
const relativeTo = new Temporal.PlainDate(2020, 1, 1);
|
||||
|
||||
const expected = [
|
||||
["years", [6], [-6]],
|
||||
["months", [5, 8], [-5, -8]],
|
||||
["weeks", [5, 6, 8], [-5, -6, -8]],
|
||||
["days", [5, 6, 7, 10], [-5, -6, -7, -10]],
|
||||
["hours", [5, 6, 7, 9, 17], [-5, -6, -7, -9, -17]],
|
||||
["minutes", [5, 6, 7, 9, 16, 30], [-5, -6, -7, -9, -16, -30]],
|
||||
["seconds", [5, 6, 7, 9, 16, 30, 20], [-5, -6, -7, -9, -16, -30, -20]],
|
||||
["milliseconds", [5, 6, 7, 9, 16, 30, 20, 124], [-5, -6, -7, -9, -16, -30, -20, -124]],
|
||||
["microseconds", [5, 6, 7, 9, 16, 30, 20, 123, 501], [-5, -6, -7, -9, -16, -30, -20, -123, -501]],
|
||||
["nanoseconds", [5, 6, 7, 9, 16, 30, 20, 123, 500, 987], [-5, -6, -7, -9, -16, -30, -20, -123, -500, -987]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfCeil";
|
||||
|
||||
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(
|
||||
instance.round({ smallestUnit, relativeTo, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
instance.negated().round({ smallestUnit, relativeTo, 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/Duration/prototype/round/roundingmode-halfEven.js
vendored
Normal file
42
test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfEven.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.duration.prototype.round
|
||||
description: Tests calculations with roundingMode "halfEven".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 500, 987);
|
||||
const relativeTo = new Temporal.PlainDate(2020, 1, 1);
|
||||
|
||||
const expected = [
|
||||
["years", [6], [-6]],
|
||||
["months", [5, 8], [-5, -8]],
|
||||
["weeks", [5, 6, 8], [-5, -6, -8]],
|
||||
["days", [5, 6, 7, 10], [-5, -6, -7, -10]],
|
||||
["hours", [5, 6, 7, 9, 17], [-5, -6, -7, -9, -17]],
|
||||
["minutes", [5, 6, 7, 9, 16, 30], [-5, -6, -7, -9, -16, -30]],
|
||||
["seconds", [5, 6, 7, 9, 16, 30, 20], [-5, -6, -7, -9, -16, -30, -20]],
|
||||
["milliseconds", [5, 6, 7, 9, 16, 30, 20, 124], [-5, -6, -7, -9, -16, -30, -20, -124]],
|
||||
["microseconds", [5, 6, 7, 9, 16, 30, 20, 123, 501], [-5, -6, -7, -9, -16, -30, -20, -123, -501]],
|
||||
["nanoseconds", [5, 6, 7, 9, 16, 30, 20, 123, 500, 987], [-5, -6, -7, -9, -16, -30, -20, -123, -500, -987]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfEven";
|
||||
|
||||
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(
|
||||
instance.round({ smallestUnit, relativeTo, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
instance.negated().round({ smallestUnit, relativeTo, 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/Duration/prototype/round/roundingmode-halfFloor.js
vendored
Normal file
42
test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfFloor.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.duration.prototype.round
|
||||
description: Tests calculations with roundingMode "halfFloor".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 500, 987);
|
||||
const relativeTo = new Temporal.PlainDate(2020, 1, 1);
|
||||
|
||||
const expected = [
|
||||
["years", [6], [-6]],
|
||||
["months", [5, 8], [-5, -8]],
|
||||
["weeks", [5, 6, 8], [-5, -6, -8]],
|
||||
["days", [5, 6, 7, 10], [-5, -6, -7, -10]],
|
||||
["hours", [5, 6, 7, 9, 17], [-5, -6, -7, -9, -17]],
|
||||
["minutes", [5, 6, 7, 9, 16, 30], [-5, -6, -7, -9, -16, -30]],
|
||||
["seconds", [5, 6, 7, 9, 16, 30, 20], [-5, -6, -7, -9, -16, -30, -20]],
|
||||
["milliseconds", [5, 6, 7, 9, 16, 30, 20, 124], [-5, -6, -7, -9, -16, -30, -20, -124]],
|
||||
["microseconds", [5, 6, 7, 9, 16, 30, 20, 123, 501], [-5, -6, -7, -9, -16, -30, -20, -123, -501]],
|
||||
["nanoseconds", [5, 6, 7, 9, 16, 30, 20, 123, 500, 987], [-5, -6, -7, -9, -16, -30, -20, -123, -500, -987]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfFloor";
|
||||
|
||||
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(
|
||||
instance.round({ smallestUnit, relativeTo, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
instance.negated().round({ smallestUnit, relativeTo, 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/Duration/prototype/round/roundingmode-halfTrunc.js
vendored
Normal file
42
test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfTrunc.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.duration.prototype.round
|
||||
description: Tests calculations with roundingMode "halfTrunc".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 500, 987);
|
||||
const relativeTo = new Temporal.PlainDate(2020, 1, 1);
|
||||
|
||||
const expected = [
|
||||
["years", [6], [-6]],
|
||||
["months", [5, 8], [-5, -8]],
|
||||
["weeks", [5, 6, 8], [-5, -6, -8]],
|
||||
["days", [5, 6, 7, 10], [-5, -6, -7, -10]],
|
||||
["hours", [5, 6, 7, 9, 17], [-5, -6, -7, -9, -17]],
|
||||
["minutes", [5, 6, 7, 9, 16, 30], [-5, -6, -7, -9, -16, -30]],
|
||||
["seconds", [5, 6, 7, 9, 16, 30, 20], [-5, -6, -7, -9, -16, -30, -20]],
|
||||
["milliseconds", [5, 6, 7, 9, 16, 30, 20, 124], [-5, -6, -7, -9, -16, -30, -20, -124]],
|
||||
["microseconds", [5, 6, 7, 9, 16, 30, 20, 123, 501], [-5, -6, -7, -9, -16, -30, -20, -123, -501]],
|
||||
["nanoseconds", [5, 6, 7, 9, 16, 30, 20, 123, 500, 987], [-5, -6, -7, -9, -16, -30, -20, -123, -500, -987]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfTrunc";
|
||||
|
||||
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(
|
||||
instance.round({ smallestUnit, relativeTo, roundingMode }),
|
||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||
);
|
||||
TemporalHelpers.assertDuration(
|
||||
instance.negated().round({ smallestUnit, relativeTo, roundingMode }),
|
||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||
);
|
||||
});
|
29
test/built-ins/Temporal/Instant/prototype/round/roundingmode-expand.js
vendored
Normal file
29
test/built-ins/Temporal/Instant/prototype/round/roundingmode-expand.js
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
// 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.round
|
||||
description: Tests calculations with roundingMode "expand".
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Instant(217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */);
|
||||
|
||||
const expected = [
|
||||
["hour", 217177200_000_000_000n /* 1976-11-18T15:00:00Z */],
|
||||
["minute", 217175040_000_000_000n /* 1976-11-18T14:24:00Z */],
|
||||
["second", 217175011_000_000_000n /* 1976-11-18T14:23:31Z */],
|
||||
["millisecond", 217175010_124_000_000n /* 1976-11-18T14:23:30.124Z */],
|
||||
["microsecond", 217175010_123_457_000n /* 1976-11-18T14:23:30.123457Z */],
|
||||
["nanosecond", 217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */],
|
||||
];
|
||||
|
||||
const roundingMode = "expand";
|
||||
|
||||
expected.forEach(([smallestUnit, expected]) => {
|
||||
assert.sameValue(
|
||||
instance.round({ smallestUnit, roundingMode }).epochNanoseconds,
|
||||
expected,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode})`
|
||||
);
|
||||
});
|
29
test/built-ins/Temporal/Instant/prototype/round/roundingmode-halfCeil.js
vendored
Normal file
29
test/built-ins/Temporal/Instant/prototype/round/roundingmode-halfCeil.js
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
// 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.round
|
||||
description: Tests calculations with roundingMode "halfCeil".
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Instant(217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */);
|
||||
|
||||
const expected = [
|
||||
["hour", 217173600_000_000_000n /* 1976-11-18T14:00:00Z */],
|
||||
["minute", 217175040_000_000_000n /* 1976-11-18T14:24:00Z */],
|
||||
["second", 217175010_000_000_000n /* 1976-11-18T14:23:30Z */],
|
||||
["millisecond", 217175010_123_000_000n /* 1976-11-18T14:23:30.123Z */],
|
||||
["microsecond", 217175010_123_457_000n /* 1976-11-18T14:23:30.123457Z */],
|
||||
["nanosecond", 217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */],
|
||||
];
|
||||
|
||||
const roundingMode = "halfCeil";
|
||||
|
||||
expected.forEach(([smallestUnit, expected]) => {
|
||||
assert.sameValue(
|
||||
instance.round({ smallestUnit, roundingMode }).epochNanoseconds,
|
||||
expected,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode})`
|
||||
);
|
||||
});
|
29
test/built-ins/Temporal/Instant/prototype/round/roundingmode-halfEven.js
vendored
Normal file
29
test/built-ins/Temporal/Instant/prototype/round/roundingmode-halfEven.js
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
// 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.round
|
||||
description: Tests calculations with roundingMode "halfEven".
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Instant(217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */);
|
||||
|
||||
const expected = [
|
||||
["hour", 217173600_000_000_000n /* 1976-11-18T14:00:00Z */],
|
||||
["minute", 217175040_000_000_000n /* 1976-11-18T14:24:00Z */],
|
||||
["second", 217175010_000_000_000n /* 1976-11-18T14:23:30Z */],
|
||||
["millisecond", 217175010_123_000_000n /* 1976-11-18T14:23:30.123Z */],
|
||||
["microsecond", 217175010_123_457_000n /* 1976-11-18T14:23:30.123457Z */],
|
||||
["nanosecond", 217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */],
|
||||
];
|
||||
|
||||
const roundingMode = "halfEven";
|
||||
|
||||
expected.forEach(([smallestUnit, expected]) => {
|
||||
assert.sameValue(
|
||||
instance.round({ smallestUnit, roundingMode }).epochNanoseconds,
|
||||
expected,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode})`
|
||||
);
|
||||
});
|
29
test/built-ins/Temporal/Instant/prototype/round/roundingmode-halfFloor.js
vendored
Normal file
29
test/built-ins/Temporal/Instant/prototype/round/roundingmode-halfFloor.js
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
// 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.round
|
||||
description: Tests calculations with roundingMode "halfFloor".
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Instant(217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */);
|
||||
|
||||
const expected = [
|
||||
["hour", 217173600_000_000_000n /* 1976-11-18T14:00:00Z */],
|
||||
["minute", 217175040_000_000_000n /* 1976-11-18T14:24:00Z */],
|
||||
["second", 217175010_000_000_000n /* 1976-11-18T14:23:30Z */],
|
||||
["millisecond", 217175010_123_000_000n /* 1976-11-18T14:23:30.123Z */],
|
||||
["microsecond", 217175010_123_457_000n /* 1976-11-18T14:23:30.123457Z */],
|
||||
["nanosecond", 217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */],
|
||||
];
|
||||
|
||||
const roundingMode = "halfFloor";
|
||||
|
||||
expected.forEach(([smallestUnit, expected]) => {
|
||||
assert.sameValue(
|
||||
instance.round({ smallestUnit, roundingMode }).epochNanoseconds,
|
||||
expected,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode})`
|
||||
);
|
||||
});
|
29
test/built-ins/Temporal/Instant/prototype/round/roundingmode-halfTrunc.js
vendored
Normal file
29
test/built-ins/Temporal/Instant/prototype/round/roundingmode-halfTrunc.js
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
// 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.round
|
||||
description: Tests calculations with roundingMode "halfTrunc".
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Instant(217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */);
|
||||
|
||||
const expected = [
|
||||
["hour", 217173600_000_000_000n /* 1976-11-18T14:00:00Z */],
|
||||
["minute", 217175040_000_000_000n /* 1976-11-18T14:24:00Z */],
|
||||
["second", 217175010_000_000_000n /* 1976-11-18T14:23:30Z */],
|
||||
["millisecond", 217175010_123_000_000n /* 1976-11-18T14:23:30.123Z */],
|
||||
["microsecond", 217175010_123_457_000n /* 1976-11-18T14:23:30.123457Z */],
|
||||
["nanosecond", 217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */],
|
||||
];
|
||||
|
||||
const roundingMode = "halfTrunc";
|
||||
|
||||
expected.forEach(([smallestUnit, expected]) => {
|
||||
assert.sameValue(
|
||||
instance.round({ smallestUnit, roundingMode }).epochNanoseconds,
|
||||
expected,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode})`
|
||||
);
|
||||
});
|
39
test/built-ins/Temporal/Instant/prototype/since/roundingmode-expand.js
vendored
Normal file
39
test/built-ins/Temporal/Instant/prototype/since/roundingmode-expand.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 "expand".
|
||||
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, -376436]],
|
||||
["minutes", [0, 0, 0, 0, 376435, 24], [0, 0, 0, 0, -376435, -24]],
|
||||
["seconds", [0, 0, 0, 0, 376435, 23, 9], [0, 0, 0, 0, -376435, -23, -9]],
|
||||
["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, 530], [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 = "expand";
|
||||
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-halfCeil.js
vendored
Normal file
39
test/built-ins/Temporal/Instant/prototype/since/roundingmode-halfCeil.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 "halfCeil".
|
||||
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 = "halfCeil";
|
||||
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-halfEven.js
vendored
Normal file
39
test/built-ins/Temporal/Instant/prototype/since/roundingmode-halfEven.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 "halfEven".
|
||||
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 = "halfEven";
|
||||
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-halfFloor.js
vendored
Normal file
39
test/built-ins/Temporal/Instant/prototype/since/roundingmode-halfFloor.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 "halfFloor".
|
||||
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 = "halfFloor";
|
||||
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-halfTrunc.js
vendored
Normal file
39
test/built-ins/Temporal/Instant/prototype/since/roundingmode-halfTrunc.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 "halfTrunc".
|
||||
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 = "halfTrunc";
|
||||
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)`
|
||||
);
|
||||
});
|
37
test/built-ins/Temporal/Instant/prototype/toString/roundingmode-expand.js
vendored
Normal file
37
test/built-ins/Temporal/Instant/prototype/toString/roundingmode-expand.js
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// 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.tostring
|
||||
description: expand value for roundingMode option
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instant = new Temporal.Instant(1_000_000_000_123_987_500n);
|
||||
|
||||
const result1 = instant.toString({ smallestUnit: "microsecond", roundingMode: "expand" });
|
||||
assert.sameValue(result1, "2001-09-09T01:46:40.123988Z",
|
||||
"roundingMode is expand (with 6 digits from smallestUnit)");
|
||||
|
||||
const result2 = instant.toString({ fractionalSecondDigits: 6, roundingMode: "expand" });
|
||||
assert.sameValue(result2, "2001-09-09T01:46:40.123988Z",
|
||||
"roundingMode is expand (with 6 digits from fractionalSecondDigits)");
|
||||
|
||||
const result3 = instant.toString({ smallestUnit: "millisecond", roundingMode: "expand" });
|
||||
assert.sameValue(result3, "2001-09-09T01:46:40.124Z",
|
||||
"roundingMode is expand (with 3 digits from smallestUnit)");
|
||||
|
||||
const result4 = instant.toString({ fractionalSecondDigits: 3, roundingMode: "expand" });
|
||||
assert.sameValue(result4, "2001-09-09T01:46:40.124Z",
|
||||
"roundingMode is expand (with 3 digits from fractionalSecondDigits)");
|
||||
|
||||
const result5 = instant.toString({ smallestUnit: "second", roundingMode: "expand" });
|
||||
assert.sameValue(result5, "2001-09-09T01:46:41Z",
|
||||
"roundingMode is expand (with 0 digits from smallestUnit)");
|
||||
|
||||
const result6 = instant.toString({ fractionalSecondDigits: 0, roundingMode: "expand" });
|
||||
assert.sameValue(result6, "2001-09-09T01:46:41Z",
|
||||
"roundingMode is expand (with 0 digits from fractionalSecondDigits)");
|
||||
|
||||
const result7 = instant.toString({ smallestUnit: "minute", roundingMode: "expand" });
|
||||
assert.sameValue(result7, "2001-09-09T01:47Z", "roundingMode is expand (round to minute)");
|
37
test/built-ins/Temporal/Instant/prototype/toString/roundingmode-halfCeil.js
vendored
Normal file
37
test/built-ins/Temporal/Instant/prototype/toString/roundingmode-halfCeil.js
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// 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.tostring
|
||||
description: halfCeil value for roundingMode option
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instant = new Temporal.Instant(1_000_000_000_123_987_500n);
|
||||
|
||||
const result1 = instant.toString({ smallestUnit: "microsecond", roundingMode: "halfCeil" });
|
||||
assert.sameValue(result1, "2001-09-09T01:46:40.123988Z",
|
||||
"roundingMode is halfCeil (with 6 digits from smallestUnit)");
|
||||
|
||||
const result2 = instant.toString({ fractionalSecondDigits: 6, roundingMode: "halfCeil" });
|
||||
assert.sameValue(result2, "2001-09-09T01:46:40.123988Z",
|
||||
"roundingMode is halfCeil (with 6 digits from fractionalSecondDigits)");
|
||||
|
||||
const result3 = instant.toString({ smallestUnit: "millisecond", roundingMode: "halfCeil" });
|
||||
assert.sameValue(result3, "2001-09-09T01:46:40.124Z",
|
||||
"roundingMode is halfCeil (with 3 digits from smallestUnit)");
|
||||
|
||||
const result4 = instant.toString({ fractionalSecondDigits: 3, roundingMode: "halfCeil" });
|
||||
assert.sameValue(result4, "2001-09-09T01:46:40.124Z",
|
||||
"roundingMode is halfCeil (with 3 digits from fractionalSecondDigits)");
|
||||
|
||||
const result5 = instant.toString({ smallestUnit: "second", roundingMode: "halfCeil" });
|
||||
assert.sameValue(result5, "2001-09-09T01:46:40Z",
|
||||
"roundingMode is halfCeil (with 0 digits from smallestUnit)");
|
||||
|
||||
const result6 = instant.toString({ fractionalSecondDigits: 0, roundingMode: "halfCeil" });
|
||||
assert.sameValue(result6, "2001-09-09T01:46:40Z",
|
||||
"roundingMode is halfCeil (with 0 digits from fractionalSecondDigits)");
|
||||
|
||||
const result7 = instant.toString({ smallestUnit: "minute", roundingMode: "halfCeil" });
|
||||
assert.sameValue(result7, "2001-09-09T01:47Z", "roundingMode is halfCeil (round to minute)");
|
37
test/built-ins/Temporal/Instant/prototype/toString/roundingmode-halfEven.js
vendored
Normal file
37
test/built-ins/Temporal/Instant/prototype/toString/roundingmode-halfEven.js
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// 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.tostring
|
||||
description: halfEven value for roundingMode option
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instant = new Temporal.Instant(1_000_000_000_123_987_500n);
|
||||
|
||||
const result1 = instant.toString({ smallestUnit: "microsecond", roundingMode: "halfEven" });
|
||||
assert.sameValue(result1, "2001-09-09T01:46:40.123988Z",
|
||||
"roundingMode is halfEven (with 6 digits from smallestUnit)");
|
||||
|
||||
const result2 = instant.toString({ fractionalSecondDigits: 6, roundingMode: "halfEven" });
|
||||
assert.sameValue(result2, "2001-09-09T01:46:40.123988Z",
|
||||
"roundingMode is halfEven (with 6 digits from fractionalSecondDigits)");
|
||||
|
||||
const result3 = instant.toString({ smallestUnit: "millisecond", roundingMode: "halfEven" });
|
||||
assert.sameValue(result3, "2001-09-09T01:46:40.124Z",
|
||||
"roundingMode is halfEven (with 3 digits from smallestUnit)");
|
||||
|
||||
const result4 = instant.toString({ fractionalSecondDigits: 3, roundingMode: "halfEven" });
|
||||
assert.sameValue(result4, "2001-09-09T01:46:40.124Z",
|
||||
"roundingMode is halfEven (with 3 digits from fractionalSecondDigits)");
|
||||
|
||||
const result5 = instant.toString({ smallestUnit: "second", roundingMode: "halfEven" });
|
||||
assert.sameValue(result5, "2001-09-09T01:46:40Z",
|
||||
"roundingMode is halfEven (with 0 digits from smallestUnit)");
|
||||
|
||||
const result6 = instant.toString({ fractionalSecondDigits: 0, roundingMode: "halfEven" });
|
||||
assert.sameValue(result6, "2001-09-09T01:46:40Z",
|
||||
"roundingMode is halfEven (with 0 digits from fractionalSecondDigits)");
|
||||
|
||||
const result7 = instant.toString({ smallestUnit: "minute", roundingMode: "halfEven" });
|
||||
assert.sameValue(result7, "2001-09-09T01:47Z", "roundingMode is halfEven (round to minute)");
|
37
test/built-ins/Temporal/Instant/prototype/toString/roundingmode-halfFloor.js
vendored
Normal file
37
test/built-ins/Temporal/Instant/prototype/toString/roundingmode-halfFloor.js
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// 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.tostring
|
||||
description: halfFloor value for roundingMode option
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instant = new Temporal.Instant(1_000_000_000_123_987_500n);
|
||||
|
||||
const result1 = instant.toString({ smallestUnit: "microsecond", roundingMode: "halfFloor" });
|
||||
assert.sameValue(result1, "2001-09-09T01:46:40.123987Z",
|
||||
"roundingMode is halfFloor (with 6 digits from smallestUnit)");
|
||||
|
||||
const result2 = instant.toString({ fractionalSecondDigits: 6, roundingMode: "halfFloor" });
|
||||
assert.sameValue(result2, "2001-09-09T01:46:40.123987Z",
|
||||
"roundingMode is halfFloor (with 6 digits from fractionalSecondDigits)");
|
||||
|
||||
const result3 = instant.toString({ smallestUnit: "millisecond", roundingMode: "halfFloor" });
|
||||
assert.sameValue(result3, "2001-09-09T01:46:40.124Z",
|
||||
"roundingMode is halfFloor (with 3 digits from smallestUnit)");
|
||||
|
||||
const result4 = instant.toString({ fractionalSecondDigits: 3, roundingMode: "halfFloor" });
|
||||
assert.sameValue(result4, "2001-09-09T01:46:40.124Z",
|
||||
"roundingMode is halfFloor (with 3 digits from fractionalSecondDigits)");
|
||||
|
||||
const result5 = instant.toString({ smallestUnit: "second", roundingMode: "halfFloor" });
|
||||
assert.sameValue(result5, "2001-09-09T01:46:40Z",
|
||||
"roundingMode is halfFloor (with 0 digits from smallestUnit)");
|
||||
|
||||
const result6 = instant.toString({ fractionalSecondDigits: 0, roundingMode: "halfFloor" });
|
||||
assert.sameValue(result6, "2001-09-09T01:46:40Z",
|
||||
"roundingMode is halfFloor (with 0 digits from fractionalSecondDigits)");
|
||||
|
||||
const result7 = instant.toString({ smallestUnit: "minute", roundingMode: "halfFloor" });
|
||||
assert.sameValue(result7, "2001-09-09T01:47Z", "roundingMode is halfFloor (round to minute)");
|
37
test/built-ins/Temporal/Instant/prototype/toString/roundingmode-halfTrunc.js
vendored
Normal file
37
test/built-ins/Temporal/Instant/prototype/toString/roundingmode-halfTrunc.js
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// 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.tostring
|
||||
description: halfTrunc value for roundingMode option
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instant = new Temporal.Instant(1_000_000_000_123_987_500n);
|
||||
|
||||
const result1 = instant.toString({ smallestUnit: "microsecond", roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result1, "2001-09-09T01:46:40.123987Z",
|
||||
"roundingMode is halfTrunc (with 6 digits from smallestUnit)");
|
||||
|
||||
const result2 = instant.toString({ fractionalSecondDigits: 6, roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result2, "2001-09-09T01:46:40.123987Z",
|
||||
"roundingMode is halfTrunc (with 6 digits from fractionalSecondDigits)");
|
||||
|
||||
const result3 = instant.toString({ smallestUnit: "millisecond", roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result3, "2001-09-09T01:46:40.124Z",
|
||||
"roundingMode is halfTrunc (with 3 digits from smallestUnit)");
|
||||
|
||||
const result4 = instant.toString({ fractionalSecondDigits: 3, roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result4, "2001-09-09T01:46:40.124Z",
|
||||
"roundingMode is halfTrunc (with 3 digits from fractionalSecondDigits)");
|
||||
|
||||
const result5 = instant.toString({ smallestUnit: "second", roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result5, "2001-09-09T01:46:40Z",
|
||||
"roundingMode is halfTrunc (with 0 digits from smallestUnit)");
|
||||
|
||||
const result6 = instant.toString({ fractionalSecondDigits: 0, roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result6, "2001-09-09T01:46:40Z",
|
||||
"roundingMode is halfTrunc (with 0 digits from fractionalSecondDigits)");
|
||||
|
||||
const result7 = instant.toString({ smallestUnit: "minute", roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result7, "2001-09-09T01:47Z", "roundingMode is halfTrunc (round to minute)");
|
39
test/built-ins/Temporal/Instant/prototype/until/roundingmode-expand.js
vendored
Normal file
39
test/built-ins/Temporal/Instant/prototype/until/roundingmode-expand.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 "expand".
|
||||
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, -376436]],
|
||||
["minutes", [0, 0, 0, 0, 376435, 24], [0, 0, 0, 0, -376435, -24]],
|
||||
["seconds", [0, 0, 0, 0, 376435, 23, 9], [0, 0, 0, 0, -376435, -23, -9]],
|
||||
["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, 530], [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 = "expand";
|
||||
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-halfCeil.js
vendored
Normal file
39
test/built-ins/Temporal/Instant/prototype/until/roundingmode-halfCeil.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 "halfCeil".
|
||||
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 = "halfCeil";
|
||||
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-halfEven.js
vendored
Normal file
39
test/built-ins/Temporal/Instant/prototype/until/roundingmode-halfEven.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 "halfEven".
|
||||
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 = "halfEven";
|
||||
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-halfFloor.js
vendored
Normal file
39
test/built-ins/Temporal/Instant/prototype/until/roundingmode-halfFloor.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 "halfFloor".
|
||||
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 = "halfFloor";
|
||||
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-halfTrunc.js
vendored
Normal file
39
test/built-ins/Temporal/Instant/prototype/until/roundingmode-halfTrunc.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 "halfTrunc".
|
||||
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 = "halfTrunc";
|
||||
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)`
|
||||
);
|
||||
});
|
36
test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-expand.js
vendored
Normal file
36
test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-expand.js
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate.prototype.since
|
||||
description: Tests calculations with roundingMode "expand".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainDate(2019, 1, 8);
|
||||
const later = new Temporal.PlainDate(2021, 9, 7);
|
||||
|
||||
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]],
|
||||
];
|
||||
|
||||
const roundingMode = "expand";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
36
test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfCeil.js
vendored
Normal file
36
test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfCeil.js
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate.prototype.since
|
||||
description: Tests calculations with roundingMode "halfCeil".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainDate(2019, 1, 8);
|
||||
const later = new Temporal.PlainDate(2021, 9, 7);
|
||||
|
||||
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]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfCeil";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
36
test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfEven.js
vendored
Normal file
36
test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfEven.js
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate.prototype.since
|
||||
description: Tests calculations with roundingMode "halfEven".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainDate(2019, 1, 8);
|
||||
const later = new Temporal.PlainDate(2021, 9, 7);
|
||||
|
||||
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]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfEven";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
36
test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfFloor.js
vendored
Normal file
36
test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfFloor.js
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate.prototype.since
|
||||
description: Tests calculations with roundingMode "halfFloor".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainDate(2019, 1, 8);
|
||||
const later = new Temporal.PlainDate(2021, 9, 7);
|
||||
|
||||
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]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfFloor";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
36
test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfTrunc.js
vendored
Normal file
36
test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfTrunc.js
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate.prototype.since
|
||||
description: Tests calculations with roundingMode "halfTrunc".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainDate(2019, 1, 8);
|
||||
const later = new Temporal.PlainDate(2021, 9, 7);
|
||||
|
||||
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]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfTrunc";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
36
test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-expand.js
vendored
Normal file
36
test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-expand.js
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate.prototype.until
|
||||
description: Tests calculations with roundingMode "expand".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainDate(2019, 1, 8);
|
||||
const later = new Temporal.PlainDate(2021, 9, 7);
|
||||
|
||||
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]],
|
||||
];
|
||||
|
||||
const roundingMode = "expand";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
36
test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfCeil.js
vendored
Normal file
36
test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfCeil.js
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate.prototype.until
|
||||
description: Tests calculations with roundingMode "halfCeil".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainDate(2019, 1, 8);
|
||||
const later = new Temporal.PlainDate(2021, 9, 7);
|
||||
|
||||
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]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfCeil";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
36
test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfEven.js
vendored
Normal file
36
test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfEven.js
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate.prototype.until
|
||||
description: Tests calculations with roundingMode "halfEven".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainDate(2019, 1, 8);
|
||||
const later = new Temporal.PlainDate(2021, 9, 7);
|
||||
|
||||
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]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfEven";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
36
test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfFloor.js
vendored
Normal file
36
test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfFloor.js
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate.prototype.until
|
||||
description: Tests calculations with roundingMode "halfFloor".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainDate(2019, 1, 8);
|
||||
const later = new Temporal.PlainDate(2021, 9, 7);
|
||||
|
||||
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]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfFloor";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
36
test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfTrunc.js
vendored
Normal file
36
test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfTrunc.js
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate.prototype.until
|
||||
description: Tests calculations with roundingMode "halfTrunc".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainDate(2019, 1, 8);
|
||||
const later = new Temporal.PlainDate(2021, 9, 7);
|
||||
|
||||
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]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfTrunc";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
32
test/built-ins/Temporal/PlainDateTime/prototype/round/roundingmode-expand.js
vendored
Normal file
32
test/built-ins/Temporal/PlainDateTime/prototype/round/roundingmode-expand.js
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
// 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.round
|
||||
description: Tests calculations with roundingMode "expand".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDateTime(1976, 11, 18, 14, 23, 30, 123, 456, 789);
|
||||
|
||||
const expected = [
|
||||
["day", [1976, 11, 'M11', 19]],
|
||||
["hour", [1976, 11, 'M11', 18, 15]],
|
||||
["minute", [1976, 11, 'M11', 18, 14, 24]],
|
||||
["second", [1976, 11, 'M11', 18, 14, 23, 31]],
|
||||
["millisecond", [1976, 11, 'M11', 18, 14, 23, 30, 124]],
|
||||
["microsecond", [1976, 11, 'M11', 18, 14, 23, 30, 123, 457]],
|
||||
["nanosecond", [1976, 11, 'M11', 18, 14, 23, 30, 123, 456, 789]],
|
||||
];
|
||||
|
||||
const roundingMode = "expand";
|
||||
|
||||
expected.forEach(([smallestUnit, expected]) => {
|
||||
const [y, mon, mc, d, h = 0, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected;
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
instance.round({ smallestUnit, roundingMode }),
|
||||
y, mon, mc, d, h, min, s, ms, µs, ns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode})`
|
||||
);
|
||||
});
|
32
test/built-ins/Temporal/PlainDateTime/prototype/round/roundingmode-halfCeil.js
vendored
Normal file
32
test/built-ins/Temporal/PlainDateTime/prototype/round/roundingmode-halfCeil.js
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
// 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.round
|
||||
description: Tests calculations with roundingMode "halfCeil".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDateTime(1976, 11, 18, 14, 23, 30, 123, 456, 789);
|
||||
|
||||
const expected = [
|
||||
["day", [1976, 11, 'M11', 19]],
|
||||
["hour", [1976, 11, 'M11', 18, 14]],
|
||||
["minute", [1976, 11, 'M11', 18, 14, 24]],
|
||||
["second", [1976, 11, 'M11', 18, 14, 23, 30]],
|
||||
["millisecond", [1976, 11, 'M11', 18, 14, 23, 30, 123]],
|
||||
["microsecond", [1976, 11, 'M11', 18, 14, 23, 30, 123, 457]],
|
||||
["nanosecond", [1976, 11, 'M11', 18, 14, 23, 30, 123, 456, 789]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfCeil";
|
||||
|
||||
expected.forEach(([smallestUnit, expected]) => {
|
||||
const [y, mon, mc, d, h = 0, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected;
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
instance.round({ smallestUnit, roundingMode }),
|
||||
y, mon, mc, d, h, min, s, ms, µs, ns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode})`
|
||||
);
|
||||
});
|
32
test/built-ins/Temporal/PlainDateTime/prototype/round/roundingmode-halfEven.js
vendored
Normal file
32
test/built-ins/Temporal/PlainDateTime/prototype/round/roundingmode-halfEven.js
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
// 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.round
|
||||
description: Tests calculations with roundingMode "halfEven".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDateTime(1976, 11, 18, 14, 23, 30, 123, 456, 789);
|
||||
|
||||
const expected = [
|
||||
["day", [1976, 11, 'M11', 19]],
|
||||
["hour", [1976, 11, 'M11', 18, 14]],
|
||||
["minute", [1976, 11, 'M11', 18, 14, 24]],
|
||||
["second", [1976, 11, 'M11', 18, 14, 23, 30]],
|
||||
["millisecond", [1976, 11, 'M11', 18, 14, 23, 30, 123]],
|
||||
["microsecond", [1976, 11, 'M11', 18, 14, 23, 30, 123, 457]],
|
||||
["nanosecond", [1976, 11, 'M11', 18, 14, 23, 30, 123, 456, 789]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfEven";
|
||||
|
||||
expected.forEach(([smallestUnit, expected]) => {
|
||||
const [y, mon, mc, d, h = 0, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected;
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
instance.round({ smallestUnit, roundingMode }),
|
||||
y, mon, mc, d, h, min, s, ms, µs, ns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode})`
|
||||
);
|
||||
});
|
32
test/built-ins/Temporal/PlainDateTime/prototype/round/roundingmode-halfFloor.js
vendored
Normal file
32
test/built-ins/Temporal/PlainDateTime/prototype/round/roundingmode-halfFloor.js
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
// 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.round
|
||||
description: Tests calculations with roundingMode "halfFloor".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDateTime(1976, 11, 18, 14, 23, 30, 123, 456, 789);
|
||||
|
||||
const expected = [
|
||||
["day", [1976, 11, 'M11', 19]],
|
||||
["hour", [1976, 11, 'M11', 18, 14]],
|
||||
["minute", [1976, 11, 'M11', 18, 14, 24]],
|
||||
["second", [1976, 11, 'M11', 18, 14, 23, 30]],
|
||||
["millisecond", [1976, 11, 'M11', 18, 14, 23, 30, 123]],
|
||||
["microsecond", [1976, 11, 'M11', 18, 14, 23, 30, 123, 457]],
|
||||
["nanosecond", [1976, 11, 'M11', 18, 14, 23, 30, 123, 456, 789]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfFloor";
|
||||
|
||||
expected.forEach(([smallestUnit, expected]) => {
|
||||
const [y, mon, mc, d, h = 0, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected;
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
instance.round({ smallestUnit, roundingMode }),
|
||||
y, mon, mc, d, h, min, s, ms, µs, ns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode})`
|
||||
);
|
||||
});
|
32
test/built-ins/Temporal/PlainDateTime/prototype/round/roundingmode-halfTrunc.js
vendored
Normal file
32
test/built-ins/Temporal/PlainDateTime/prototype/round/roundingmode-halfTrunc.js
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
// 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.round
|
||||
description: Tests calculations with roundingMode "halfTrunc".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDateTime(1976, 11, 18, 14, 23, 30, 123, 456, 789);
|
||||
|
||||
const expected = [
|
||||
["day", [1976, 11, 'M11', 19]],
|
||||
["hour", [1976, 11, 'M11', 18, 14]],
|
||||
["minute", [1976, 11, 'M11', 18, 14, 24]],
|
||||
["second", [1976, 11, 'M11', 18, 14, 23, 30]],
|
||||
["millisecond", [1976, 11, 'M11', 18, 14, 23, 30, 123]],
|
||||
["microsecond", [1976, 11, 'M11', 18, 14, 23, 30, 123, 457]],
|
||||
["nanosecond", [1976, 11, 'M11', 18, 14, 23, 30, 123, 456, 789]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfTrunc";
|
||||
|
||||
expected.forEach(([smallestUnit, expected]) => {
|
||||
const [y, mon, mc, d, h = 0, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected;
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
instance.round({ smallestUnit, roundingMode }),
|
||||
y, mon, mc, d, h, min, s, ms, µs, ns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode})`
|
||||
);
|
||||
});
|
42
test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-expand.js
vendored
Normal file
42
test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-expand.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 "expand".
|
||||
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, 140], [0, 0, -140]],
|
||||
["days", [0, 0, 0, 974], [0, 0, 0, -974]],
|
||||
["hours", [0, 0, 0, 973, 5], [0, 0, 0, -973, -5]],
|
||||
["minutes", [0, 0, 0, 973, 4, 18], [0, 0, 0, -973, -4, -18]],
|
||||
["seconds", [0, 0, 0, 973, 4, 17, 5], [0, 0, 0, -973, -4, -17, -5]],
|
||||
["milliseconds", [0, 0, 0, 973, 4, 17, 4, 865], [0, 0, 0, -973, -4, -17, -4, -865]],
|
||||
["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 = "expand";
|
||||
|
||||
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/PlainDateTime/prototype/since/roundingmode-halfCeil.js
vendored
Normal file
42
test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-halfCeil.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 "halfCeil".
|
||||
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 = "halfCeil";
|
||||
|
||||
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/PlainDateTime/prototype/since/roundingmode-halfEven.js
vendored
Normal file
42
test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-halfEven.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 "halfEven".
|
||||
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 = "halfEven";
|
||||
|
||||
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/PlainDateTime/prototype/since/roundingmode-halfFloor.js
vendored
Normal file
42
test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-halfFloor.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 "halfFloor".
|
||||
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 = "halfFloor";
|
||||
|
||||
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/PlainDateTime/prototype/since/roundingmode-halfTrunc.js
vendored
Normal file
42
test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-halfTrunc.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 "halfTrunc".
|
||||
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 = "halfTrunc";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
37
test/built-ins/Temporal/PlainDateTime/prototype/toString/roundingmode-expand.js
vendored
Normal file
37
test/built-ins/Temporal/PlainDateTime/prototype/toString/roundingmode-expand.js
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// 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.tostring
|
||||
description: expand value for roundingMode option
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 123, 987, 500);
|
||||
|
||||
const result1 = datetime.toString({ smallestUnit: "microsecond", roundingMode: "expand" });
|
||||
assert.sameValue(result1, "2000-05-02T12:34:56.123988",
|
||||
"roundingMode is expand (with 6 digits from smallestUnit)");
|
||||
|
||||
const result2 = datetime.toString({ fractionalSecondDigits: 6, roundingMode: "expand" });
|
||||
assert.sameValue(result2, "2000-05-02T12:34:56.123988",
|
||||
"roundingMode is expand (with 6 digits from fractionalSecondDigits)");
|
||||
|
||||
const result3 = datetime.toString({ smallestUnit: "millisecond", roundingMode: "expand" });
|
||||
assert.sameValue(result3, "2000-05-02T12:34:56.124",
|
||||
"roundingMode is expand (with 3 digits from smallestUnit)");
|
||||
|
||||
const result4 = datetime.toString({ fractionalSecondDigits: 3, roundingMode: "expand" });
|
||||
assert.sameValue(result4, "2000-05-02T12:34:56.124",
|
||||
"roundingMode is expand (with 3 digits from fractionalSecondDigits)");
|
||||
|
||||
const result5 = datetime.toString({ smallestUnit: "second", roundingMode: "expand" });
|
||||
assert.sameValue(result5, "2000-05-02T12:34:57",
|
||||
"roundingMode is expand (with 0 digits from smallestUnit)");
|
||||
|
||||
const result6 = datetime.toString({ fractionalSecondDigits: 0, roundingMode: "expand" });
|
||||
assert.sameValue(result6, "2000-05-02T12:34:57",
|
||||
"roundingMode is expand (with 0 digits from fractionalSecondDigits)");
|
||||
|
||||
const result7 = datetime.toString({ smallestUnit: "minute", roundingMode: "expand" });
|
||||
assert.sameValue(result7, "2000-05-02T12:35", "roundingMode is expand (round to minute)");
|
37
test/built-ins/Temporal/PlainDateTime/prototype/toString/roundingmode-halfCeil.js
vendored
Normal file
37
test/built-ins/Temporal/PlainDateTime/prototype/toString/roundingmode-halfCeil.js
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// 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.tostring
|
||||
description: halfCeil value for roundingMode option
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 123, 987, 500);
|
||||
|
||||
const result1 = datetime.toString({ smallestUnit: "microsecond", roundingMode: "halfCeil" });
|
||||
assert.sameValue(result1, "2000-05-02T12:34:56.123988",
|
||||
"roundingMode is halfCeil (with 6 digits from smallestUnit)");
|
||||
|
||||
const result2 = datetime.toString({ fractionalSecondDigits: 6, roundingMode: "halfCeil" });
|
||||
assert.sameValue(result2, "2000-05-02T12:34:56.123988",
|
||||
"roundingMode is halfCeil (with 6 digits from fractionalSecondDigits)");
|
||||
|
||||
const result3 = datetime.toString({ smallestUnit: "millisecond", roundingMode: "halfCeil" });
|
||||
assert.sameValue(result3, "2000-05-02T12:34:56.124",
|
||||
"roundingMode is halfCeil (with 3 digits from smallestUnit)");
|
||||
|
||||
const result4 = datetime.toString({ fractionalSecondDigits: 3, roundingMode: "halfCeil" });
|
||||
assert.sameValue(result4, "2000-05-02T12:34:56.124",
|
||||
"roundingMode is halfCeil (with 3 digits from fractionalSecondDigits)");
|
||||
|
||||
const result5 = datetime.toString({ smallestUnit: "second", roundingMode: "halfCeil" });
|
||||
assert.sameValue(result5, "2000-05-02T12:34:56",
|
||||
"roundingMode is halfCeil (with 0 digits from smallestUnit)");
|
||||
|
||||
const result6 = datetime.toString({ fractionalSecondDigits: 0, roundingMode: "halfCeil" });
|
||||
assert.sameValue(result6, "2000-05-02T12:34:56",
|
||||
"roundingMode is halfCeil (with 0 digits from fractionalSecondDigits)");
|
||||
|
||||
const result7 = datetime.toString({ smallestUnit: "minute", roundingMode: "halfCeil" });
|
||||
assert.sameValue(result7, "2000-05-02T12:35", "roundingMode is halfCeil (round to minute)");
|
37
test/built-ins/Temporal/PlainDateTime/prototype/toString/roundingmode-halfEven.js
vendored
Normal file
37
test/built-ins/Temporal/PlainDateTime/prototype/toString/roundingmode-halfEven.js
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// 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.tostring
|
||||
description: halfEven value for roundingMode option
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 123, 987, 500);
|
||||
|
||||
const result1 = datetime.toString({ smallestUnit: "microsecond", roundingMode: "halfEven" });
|
||||
assert.sameValue(result1, "2000-05-02T12:34:56.123988",
|
||||
"roundingMode is halfEven (with 6 digits from smallestUnit)");
|
||||
|
||||
const result2 = datetime.toString({ fractionalSecondDigits: 6, roundingMode: "halfEven" });
|
||||
assert.sameValue(result2, "2000-05-02T12:34:56.123988",
|
||||
"roundingMode is halfEven (with 6 digits from fractionalSecondDigits)");
|
||||
|
||||
const result3 = datetime.toString({ smallestUnit: "millisecond", roundingMode: "halfEven" });
|
||||
assert.sameValue(result3, "2000-05-02T12:34:56.124",
|
||||
"roundingMode is halfEven (with 3 digits from smallestUnit)");
|
||||
|
||||
const result4 = datetime.toString({ fractionalSecondDigits: 3, roundingMode: "halfEven" });
|
||||
assert.sameValue(result4, "2000-05-02T12:34:56.124",
|
||||
"roundingMode is halfEven (with 3 digits from fractionalSecondDigits)");
|
||||
|
||||
const result5 = datetime.toString({ smallestUnit: "second", roundingMode: "halfEven" });
|
||||
assert.sameValue(result5, "2000-05-02T12:34:56",
|
||||
"roundingMode is halfEven (with 0 digits from smallestUnit)");
|
||||
|
||||
const result6 = datetime.toString({ fractionalSecondDigits: 0, roundingMode: "halfEven" });
|
||||
assert.sameValue(result6, "2000-05-02T12:34:56",
|
||||
"roundingMode is halfEven (with 0 digits from fractionalSecondDigits)");
|
||||
|
||||
const result7 = datetime.toString({ smallestUnit: "minute", roundingMode: "halfEven" });
|
||||
assert.sameValue(result7, "2000-05-02T12:35", "roundingMode is halfEven (round to minute)");
|
37
test/built-ins/Temporal/PlainDateTime/prototype/toString/roundingmode-halfFloor.js
vendored
Normal file
37
test/built-ins/Temporal/PlainDateTime/prototype/toString/roundingmode-halfFloor.js
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// 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.tostring
|
||||
description: halfFloor value for roundingMode option
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 123, 987, 500);
|
||||
|
||||
const result1 = datetime.toString({ smallestUnit: "microsecond", roundingMode: "halfFloor" });
|
||||
assert.sameValue(result1, "2000-05-02T12:34:56.123987",
|
||||
"roundingMode is halfFloor (with 6 digits from smallestUnit)");
|
||||
|
||||
const result2 = datetime.toString({ fractionalSecondDigits: 6, roundingMode: "halfFloor" });
|
||||
assert.sameValue(result2, "2000-05-02T12:34:56.123987",
|
||||
"roundingMode is halfFloor (with 6 digits from fractionalSecondDigits)");
|
||||
|
||||
const result3 = datetime.toString({ smallestUnit: "millisecond", roundingMode: "halfFloor" });
|
||||
assert.sameValue(result3, "2000-05-02T12:34:56.124",
|
||||
"roundingMode is halfFloor (with 3 digits from smallestUnit)");
|
||||
|
||||
const result4 = datetime.toString({ fractionalSecondDigits: 3, roundingMode: "halfFloor" });
|
||||
assert.sameValue(result4, "2000-05-02T12:34:56.124",
|
||||
"roundingMode is halfFloor (with 3 digits from fractionalSecondDigits)");
|
||||
|
||||
const result5 = datetime.toString({ smallestUnit: "second", roundingMode: "halfFloor" });
|
||||
assert.sameValue(result5, "2000-05-02T12:34:56",
|
||||
"roundingMode is halfFloor (with 0 digits from smallestUnit)");
|
||||
|
||||
const result6 = datetime.toString({ fractionalSecondDigits: 0, roundingMode: "halfFloor" });
|
||||
assert.sameValue(result6, "2000-05-02T12:34:56",
|
||||
"roundingMode is halfFloor (with 0 digits from fractionalSecondDigits)");
|
||||
|
||||
const result7 = datetime.toString({ smallestUnit: "minute", roundingMode: "halfFloor" });
|
||||
assert.sameValue(result7, "2000-05-02T12:35", "roundingMode is halfFloor (round to minute)");
|
37
test/built-ins/Temporal/PlainDateTime/prototype/toString/roundingmode-halfTrunc.js
vendored
Normal file
37
test/built-ins/Temporal/PlainDateTime/prototype/toString/roundingmode-halfTrunc.js
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// 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.tostring
|
||||
description: halfTrunc value for roundingMode option
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 123, 987, 500);
|
||||
|
||||
const result1 = datetime.toString({ smallestUnit: "microsecond", roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result1, "2000-05-02T12:34:56.123987",
|
||||
"roundingMode is halfTrunc (with 6 digits from smallestUnit)");
|
||||
|
||||
const result2 = datetime.toString({ fractionalSecondDigits: 6, roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result2, "2000-05-02T12:34:56.123987",
|
||||
"roundingMode is halfTrunc (with 6 digits from fractionalSecondDigits)");
|
||||
|
||||
const result3 = datetime.toString({ smallestUnit: "millisecond", roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result3, "2000-05-02T12:34:56.124",
|
||||
"roundingMode is halfTrunc (with 3 digits from smallestUnit)");
|
||||
|
||||
const result4 = datetime.toString({ fractionalSecondDigits: 3, roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result4, "2000-05-02T12:34:56.124",
|
||||
"roundingMode is halfTrunc (with 3 digits from fractionalSecondDigits)");
|
||||
|
||||
const result5 = datetime.toString({ smallestUnit: "second", roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result5, "2000-05-02T12:34:56",
|
||||
"roundingMode is halfTrunc (with 0 digits from smallestUnit)");
|
||||
|
||||
const result6 = datetime.toString({ fractionalSecondDigits: 0, roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result6, "2000-05-02T12:34:56",
|
||||
"roundingMode is halfTrunc (with 0 digits from fractionalSecondDigits)");
|
||||
|
||||
const result7 = datetime.toString({ smallestUnit: "minute", roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result7, "2000-05-02T12:35", "roundingMode is halfTrunc (round to minute)");
|
42
test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-expand.js
vendored
Normal file
42
test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-expand.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 "expand".
|
||||
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, 140], [0, 0, -140]],
|
||||
["days", [0, 0, 0, 974], [0, 0, 0, -974]],
|
||||
["hours", [0, 0, 0, 973, 5], [0, 0, 0, -973, -5]],
|
||||
["minutes", [0, 0, 0, 973, 4, 18], [0, 0, 0, -973, -4, -18]],
|
||||
["seconds", [0, 0, 0, 973, 4, 17, 5], [0, 0, 0, -973, -4, -17, -5]],
|
||||
["milliseconds", [0, 0, 0, 973, 4, 17, 4, 865], [0, 0, 0, -973, -4, -17, -4, -865]],
|
||||
["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 = "expand";
|
||||
|
||||
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/PlainDateTime/prototype/until/roundingmode-halfCeil.js
vendored
Normal file
42
test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-halfCeil.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 "halfCeil".
|
||||
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 = "halfCeil";
|
||||
|
||||
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/PlainDateTime/prototype/until/roundingmode-halfEven.js
vendored
Normal file
42
test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-halfEven.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 "halfEven".
|
||||
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 = "halfEven";
|
||||
|
||||
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/PlainDateTime/prototype/until/roundingmode-halfFloor.js
vendored
Normal file
42
test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-halfFloor.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 "halfFloor".
|
||||
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 = "halfFloor";
|
||||
|
||||
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/PlainDateTime/prototype/until/roundingmode-halfTrunc.js
vendored
Normal file
42
test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-halfTrunc.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 "halfTrunc".
|
||||
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 = "halfTrunc";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
31
test/built-ins/Temporal/PlainTime/prototype/round/roundingmode-expand.js
vendored
Normal file
31
test/built-ins/Temporal/PlainTime/prototype/round/roundingmode-expand.js
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
// 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.plaintime.prototype.round
|
||||
description: Tests calculations with roundingMode "expand".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainTime(13, 46, 23, 123, 456, 789);
|
||||
|
||||
const expected = [
|
||||
["hour", [14]],
|
||||
["minute", [13, 47]],
|
||||
["second", [13, 46, 24]],
|
||||
["millisecond", [13, 46, 23, 124]],
|
||||
["microsecond", [13, 46, 23, 123, 457]],
|
||||
["nanosecond", [13, 46, 23, 123, 456, 789]],
|
||||
];
|
||||
|
||||
const roundingMode = "expand";
|
||||
|
||||
expected.forEach(([smallestUnit, expected]) => {
|
||||
const [h, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected;
|
||||
TemporalHelpers.assertPlainTime(
|
||||
instance.round({ smallestUnit, roundingMode }),
|
||||
h, min, s, ms, µs, ns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode})`
|
||||
);
|
||||
});
|
31
test/built-ins/Temporal/PlainTime/prototype/round/roundingmode-halfCeil.js
vendored
Normal file
31
test/built-ins/Temporal/PlainTime/prototype/round/roundingmode-halfCeil.js
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
// 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.plaintime.prototype.round
|
||||
description: Tests calculations with roundingMode "halfCeil".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainTime(13, 46, 23, 123, 456, 789);
|
||||
|
||||
const expected = [
|
||||
["hour", [14]],
|
||||
["minute", [13, 46]],
|
||||
["second", [13, 46, 23]],
|
||||
["millisecond", [13, 46, 23, 123]],
|
||||
["microsecond", [13, 46, 23, 123, 457]],
|
||||
["nanosecond", [13, 46, 23, 123, 456, 789]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfCeil";
|
||||
|
||||
expected.forEach(([smallestUnit, expected]) => {
|
||||
const [h, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected;
|
||||
TemporalHelpers.assertPlainTime(
|
||||
instance.round({ smallestUnit, roundingMode }),
|
||||
h, min, s, ms, µs, ns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode})`
|
||||
);
|
||||
});
|
31
test/built-ins/Temporal/PlainTime/prototype/round/roundingmode-halfEven.js
vendored
Normal file
31
test/built-ins/Temporal/PlainTime/prototype/round/roundingmode-halfEven.js
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
// 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.plaintime.prototype.round
|
||||
description: Tests calculations with roundingMode "halfEven".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainTime(13, 46, 23, 123, 456, 789);
|
||||
|
||||
const expected = [
|
||||
["hour", [14]],
|
||||
["minute", [13, 46]],
|
||||
["second", [13, 46, 23]],
|
||||
["millisecond", [13, 46, 23, 123]],
|
||||
["microsecond", [13, 46, 23, 123, 457]],
|
||||
["nanosecond", [13, 46, 23, 123, 456, 789]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfEven";
|
||||
|
||||
expected.forEach(([smallestUnit, expected]) => {
|
||||
const [h, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected;
|
||||
TemporalHelpers.assertPlainTime(
|
||||
instance.round({ smallestUnit, roundingMode }),
|
||||
h, min, s, ms, µs, ns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode})`
|
||||
);
|
||||
});
|
31
test/built-ins/Temporal/PlainTime/prototype/round/roundingmode-halfFloor.js
vendored
Normal file
31
test/built-ins/Temporal/PlainTime/prototype/round/roundingmode-halfFloor.js
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
// 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.plaintime.prototype.round
|
||||
description: Tests calculations with roundingMode "halfFloor".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainTime(13, 46, 23, 123, 456, 789);
|
||||
|
||||
const expected = [
|
||||
["hour", [14]],
|
||||
["minute", [13, 46]],
|
||||
["second", [13, 46, 23]],
|
||||
["millisecond", [13, 46, 23, 123]],
|
||||
["microsecond", [13, 46, 23, 123, 457]],
|
||||
["nanosecond", [13, 46, 23, 123, 456, 789]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfFloor";
|
||||
|
||||
expected.forEach(([smallestUnit, expected]) => {
|
||||
const [h, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected;
|
||||
TemporalHelpers.assertPlainTime(
|
||||
instance.round({ smallestUnit, roundingMode }),
|
||||
h, min, s, ms, µs, ns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode})`
|
||||
);
|
||||
});
|
31
test/built-ins/Temporal/PlainTime/prototype/round/roundingmode-halfTrunc.js
vendored
Normal file
31
test/built-ins/Temporal/PlainTime/prototype/round/roundingmode-halfTrunc.js
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
// 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.plaintime.prototype.round
|
||||
description: Tests calculations with roundingMode "halfTrunc".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainTime(13, 46, 23, 123, 456, 789);
|
||||
|
||||
const expected = [
|
||||
["hour", [14]],
|
||||
["minute", [13, 46]],
|
||||
["second", [13, 46, 23]],
|
||||
["millisecond", [13, 46, 23, 123]],
|
||||
["microsecond", [13, 46, 23, 123, 457]],
|
||||
["nanosecond", [13, 46, 23, 123, 456, 789]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfTrunc";
|
||||
|
||||
expected.forEach(([smallestUnit, expected]) => {
|
||||
const [h, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected;
|
||||
TemporalHelpers.assertPlainTime(
|
||||
instance.round({ smallestUnit, roundingMode }),
|
||||
h, min, s, ms, µs, ns,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode})`
|
||||
);
|
||||
});
|
38
test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-expand.js
vendored
Normal file
38
test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-expand.js
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
// 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.plaintime.prototype.since
|
||||
description: Tests calculations with roundingMode "expand".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321);
|
||||
|
||||
const expected = [
|
||||
["hours", [0, 0, 0, 0, 5], [0, 0, 0, 0, -5]],
|
||||
["minutes", [0, 0, 0, 0, 4, 18], [0, 0, 0, 0, -4, -18]],
|
||||
["seconds", [0, 0, 0, 0, 4, 17, 5], [0, 0, 0, 0, -4, -17, -5]],
|
||||
["milliseconds", [0, 0, 0, 0, 4, 17, 4, 865], [0, 0, 0, 0, -4, -17, -4, -865]],
|
||||
["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]],
|
||||
];
|
||||
|
||||
const roundingMode = "expand";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
38
test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-halfCeil.js
vendored
Normal file
38
test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-halfCeil.js
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
// 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.plaintime.prototype.since
|
||||
description: Tests calculations with roundingMode "halfCeil".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321);
|
||||
|
||||
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]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfCeil";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
38
test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-halfEven.js
vendored
Normal file
38
test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-halfEven.js
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
// 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.plaintime.prototype.since
|
||||
description: Tests calculations with roundingMode "halfEven".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321);
|
||||
|
||||
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]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfEven";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
38
test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-halfFloor.js
vendored
Normal file
38
test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-halfFloor.js
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
// 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.plaintime.prototype.since
|
||||
description: Tests calculations with roundingMode "halfFloor".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321);
|
||||
|
||||
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]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfFloor";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
38
test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-halfTrunc.js
vendored
Normal file
38
test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-halfTrunc.js
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
// 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.plaintime.prototype.since
|
||||
description: Tests calculations with roundingMode "halfTrunc".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321);
|
||||
|
||||
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]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfTrunc";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
37
test/built-ins/Temporal/PlainTime/prototype/toString/roundingmode-expand.js
vendored
Normal file
37
test/built-ins/Temporal/PlainTime/prototype/toString/roundingmode-expand.js
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// 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.plaintime.prototype.tostring
|
||||
description: expand value for roundingMode option
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const time = new Temporal.PlainTime(12, 34, 56, 123, 987, 500);
|
||||
|
||||
const result1 = time.toString({ smallestUnit: "microsecond", roundingMode: "expand" });
|
||||
assert.sameValue(result1, "12:34:56.123988",
|
||||
"roundingMode is expand (with 6 digits from smallestUnit)");
|
||||
|
||||
const result2 = time.toString({ fractionalSecondDigits: 6, roundingMode: "expand" });
|
||||
assert.sameValue(result2, "12:34:56.123988",
|
||||
"roundingMode is expand (with 6 digits from fractionalSecondDigits)");
|
||||
|
||||
const result3 = time.toString({ smallestUnit: "millisecond", roundingMode: "expand" });
|
||||
assert.sameValue(result3, "12:34:56.124",
|
||||
"roundingMode is expand (with 3 digits from smallestUnit)");
|
||||
|
||||
const result4 = time.toString({ fractionalSecondDigits: 3, roundingMode: "expand" });
|
||||
assert.sameValue(result4, "12:34:56.124",
|
||||
"roundingMode is expand (with 3 digits from fractionalSecondDigits)");
|
||||
|
||||
const result5 = time.toString({ smallestUnit: "second", roundingMode: "expand" });
|
||||
assert.sameValue(result5, "12:34:57",
|
||||
"roundingMode is expand (with 0 digits from smallestUnit)");
|
||||
|
||||
const result6 = time.toString({ fractionalSecondDigits: 0, roundingMode: "expand" });
|
||||
assert.sameValue(result6, "12:34:57",
|
||||
"roundingMode is expand (with 0 digits from fractionalSecondDigits)");
|
||||
|
||||
const result7 = time.toString({ smallestUnit: "minute", roundingMode: "expand" });
|
||||
assert.sameValue(result7, "12:35", "roundingMode is expand (round to minute)");
|
37
test/built-ins/Temporal/PlainTime/prototype/toString/roundingmode-halfCeil.js
vendored
Normal file
37
test/built-ins/Temporal/PlainTime/prototype/toString/roundingmode-halfCeil.js
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// 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.plaintime.prototype.tostring
|
||||
description: halfCeil value for roundingMode option
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const time = new Temporal.PlainTime(12, 34, 56, 123, 987, 500);
|
||||
|
||||
const result1 = time.toString({ smallestUnit: "microsecond", roundingMode: "halfCeil" });
|
||||
assert.sameValue(result1, "12:34:56.123988",
|
||||
"roundingMode is halfCeil (with 6 digits from smallestUnit)");
|
||||
|
||||
const result2 = time.toString({ fractionalSecondDigits: 6, roundingMode: "halfCeil" });
|
||||
assert.sameValue(result2, "12:34:56.123988",
|
||||
"roundingMode is halfCeil (with 6 digits from fractionalSecondDigits)");
|
||||
|
||||
const result3 = time.toString({ smallestUnit: "millisecond", roundingMode: "halfCeil" });
|
||||
assert.sameValue(result3, "12:34:56.124",
|
||||
"roundingMode is halfCeil (with 3 digits from smallestUnit)");
|
||||
|
||||
const result4 = time.toString({ fractionalSecondDigits: 3, roundingMode: "halfCeil" });
|
||||
assert.sameValue(result4, "12:34:56.124",
|
||||
"roundingMode is halfCeil (with 3 digits from fractionalSecondDigits)");
|
||||
|
||||
const result5 = time.toString({ smallestUnit: "second", roundingMode: "halfCeil" });
|
||||
assert.sameValue(result5, "12:34:56",
|
||||
"roundingMode is halfCeil (with 0 digits from smallestUnit)");
|
||||
|
||||
const result6 = time.toString({ fractionalSecondDigits: 0, roundingMode: "halfCeil" });
|
||||
assert.sameValue(result6, "12:34:56",
|
||||
"roundingMode is halfCeil (with 0 digits from fractionalSecondDigits)");
|
||||
|
||||
const result7 = time.toString({ smallestUnit: "minute", roundingMode: "halfCeil" });
|
||||
assert.sameValue(result7, "12:35", "roundingMode is halfCeil (round to minute)");
|
37
test/built-ins/Temporal/PlainTime/prototype/toString/roundingmode-halfEven.js
vendored
Normal file
37
test/built-ins/Temporal/PlainTime/prototype/toString/roundingmode-halfEven.js
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// 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.plaintime.prototype.tostring
|
||||
description: halfEven value for roundingMode option
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const time = new Temporal.PlainTime(12, 34, 56, 123, 987, 500);
|
||||
|
||||
const result1 = time.toString({ smallestUnit: "microsecond", roundingMode: "halfEven" });
|
||||
assert.sameValue(result1, "12:34:56.123988",
|
||||
"roundingMode is halfEven (with 6 digits from smallestUnit)");
|
||||
|
||||
const result2 = time.toString({ fractionalSecondDigits: 6, roundingMode: "halfEven" });
|
||||
assert.sameValue(result2, "12:34:56.123988",
|
||||
"roundingMode is halfEven (with 6 digits from fractionalSecondDigits)");
|
||||
|
||||
const result3 = time.toString({ smallestUnit: "millisecond", roundingMode: "halfEven" });
|
||||
assert.sameValue(result3, "12:34:56.124",
|
||||
"roundingMode is halfEven (with 3 digits from smallestUnit)");
|
||||
|
||||
const result4 = time.toString({ fractionalSecondDigits: 3, roundingMode: "halfEven" });
|
||||
assert.sameValue(result4, "12:34:56.124",
|
||||
"roundingMode is halfEven (with 3 digits from fractionalSecondDigits)");
|
||||
|
||||
const result5 = time.toString({ smallestUnit: "second", roundingMode: "halfEven" });
|
||||
assert.sameValue(result5, "12:34:56",
|
||||
"roundingMode is halfEven (with 0 digits from smallestUnit)");
|
||||
|
||||
const result6 = time.toString({ fractionalSecondDigits: 0, roundingMode: "halfEven" });
|
||||
assert.sameValue(result6, "12:34:56",
|
||||
"roundingMode is halfEven (with 0 digits from fractionalSecondDigits)");
|
||||
|
||||
const result7 = time.toString({ smallestUnit: "minute", roundingMode: "halfEven" });
|
||||
assert.sameValue(result7, "12:35", "roundingMode is halfEven (round to minute)");
|
37
test/built-ins/Temporal/PlainTime/prototype/toString/roundingmode-halfFloor.js
vendored
Normal file
37
test/built-ins/Temporal/PlainTime/prototype/toString/roundingmode-halfFloor.js
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// 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.plaintime.prototype.tostring
|
||||
description: halfFloor value for roundingMode option
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const time = new Temporal.PlainTime(12, 34, 56, 123, 987, 500);
|
||||
|
||||
const result1 = time.toString({ smallestUnit: "microsecond", roundingMode: "halfFloor" });
|
||||
assert.sameValue(result1, "12:34:56.123987",
|
||||
"roundingMode is halfFloor (with 6 digits from smallestUnit)");
|
||||
|
||||
const result2 = time.toString({ fractionalSecondDigits: 6, roundingMode: "halfFloor" });
|
||||
assert.sameValue(result2, "12:34:56.123987",
|
||||
"roundingMode is halfFloor (with 6 digits from fractionalSecondDigits)");
|
||||
|
||||
const result3 = time.toString({ smallestUnit: "millisecond", roundingMode: "halfFloor" });
|
||||
assert.sameValue(result3, "12:34:56.124",
|
||||
"roundingMode is halfFloor (with 3 digits from smallestUnit)");
|
||||
|
||||
const result4 = time.toString({ fractionalSecondDigits: 3, roundingMode: "halfFloor" });
|
||||
assert.sameValue(result4, "12:34:56.124",
|
||||
"roundingMode is halfFloor (with 3 digits from fractionalSecondDigits)");
|
||||
|
||||
const result5 = time.toString({ smallestUnit: "second", roundingMode: "halfFloor" });
|
||||
assert.sameValue(result5, "12:34:56",
|
||||
"roundingMode is halfFloor (with 0 digits from smallestUnit)");
|
||||
|
||||
const result6 = time.toString({ fractionalSecondDigits: 0, roundingMode: "halfFloor" });
|
||||
assert.sameValue(result6, "12:34:56",
|
||||
"roundingMode is halfFloor (with 0 digits from fractionalSecondDigits)");
|
||||
|
||||
const result7 = time.toString({ smallestUnit: "minute", roundingMode: "halfFloor" });
|
||||
assert.sameValue(result7, "12:35", "roundingMode is halfFloor (round to minute)");
|
37
test/built-ins/Temporal/PlainTime/prototype/toString/roundingmode-halfTrunc.js
vendored
Normal file
37
test/built-ins/Temporal/PlainTime/prototype/toString/roundingmode-halfTrunc.js
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// 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.plaintime.prototype.tostring
|
||||
description: halfTrunc value for roundingMode option
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const time = new Temporal.PlainTime(12, 34, 56, 123, 987, 500);
|
||||
|
||||
const result1 = time.toString({ smallestUnit: "microsecond", roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result1, "12:34:56.123987",
|
||||
"roundingMode is halfTrunc (with 6 digits from smallestUnit)");
|
||||
|
||||
const result2 = time.toString({ fractionalSecondDigits: 6, roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result2, "12:34:56.123987",
|
||||
"roundingMode is halfTrunc (with 6 digits from fractionalSecondDigits)");
|
||||
|
||||
const result3 = time.toString({ smallestUnit: "millisecond", roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result3, "12:34:56.124",
|
||||
"roundingMode is halfTrunc (with 3 digits from smallestUnit)");
|
||||
|
||||
const result4 = time.toString({ fractionalSecondDigits: 3, roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result4, "12:34:56.124",
|
||||
"roundingMode is halfTrunc (with 3 digits from fractionalSecondDigits)");
|
||||
|
||||
const result5 = time.toString({ smallestUnit: "second", roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result5, "12:34:56",
|
||||
"roundingMode is halfTrunc (with 0 digits from smallestUnit)");
|
||||
|
||||
const result6 = time.toString({ fractionalSecondDigits: 0, roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result6, "12:34:56",
|
||||
"roundingMode is halfTrunc (with 0 digits from fractionalSecondDigits)");
|
||||
|
||||
const result7 = time.toString({ smallestUnit: "minute", roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result7, "12:35", "roundingMode is halfTrunc (round to minute)");
|
38
test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-expand.js
vendored
Normal file
38
test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-expand.js
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
// 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.plaintime.prototype.until
|
||||
description: Tests calculations with roundingMode "expand".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321);
|
||||
|
||||
const expected = [
|
||||
["hours", [0, 0, 0, 0, 5], [0, 0, 0, 0, -5]],
|
||||
["minutes", [0, 0, 0, 0, 4, 18], [0, 0, 0, 0, -4, -18]],
|
||||
["seconds", [0, 0, 0, 0, 4, 17, 5], [0, 0, 0, 0, -4, -17, -5]],
|
||||
["milliseconds", [0, 0, 0, 0, 4, 17, 4, 865], [0, 0, 0, 0, -4, -17, -4, -865]],
|
||||
["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]],
|
||||
];
|
||||
|
||||
const roundingMode = "expand";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
38
test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-halfCeil.js
vendored
Normal file
38
test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-halfCeil.js
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
// 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.plaintime.prototype.until
|
||||
description: Tests calculations with roundingMode "halfCeil".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321);
|
||||
|
||||
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]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfCeil";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
38
test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-halfEven.js
vendored
Normal file
38
test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-halfEven.js
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
// 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.plaintime.prototype.until
|
||||
description: Tests calculations with roundingMode "halfEven".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321);
|
||||
|
||||
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]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfEven";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
38
test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-halfFloor.js
vendored
Normal file
38
test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-halfFloor.js
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
// 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.plaintime.prototype.until
|
||||
description: Tests calculations with roundingMode "halfFloor".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321);
|
||||
|
||||
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]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfFloor";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
38
test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-halfTrunc.js
vendored
Normal file
38
test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-halfTrunc.js
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
// 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.plaintime.prototype.until
|
||||
description: Tests calculations with roundingMode "halfTrunc".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789);
|
||||
const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321);
|
||||
|
||||
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]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfTrunc";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
34
test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-expand.js
vendored
Normal file
34
test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-expand.js
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainyearmonth.prototype.since
|
||||
description: Tests calculations with roundingMode "expand".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainYearMonth(2019, 1);
|
||||
const later = new Temporal.PlainYearMonth(2021, 9);
|
||||
|
||||
const expected = [
|
||||
["years", [3], [-3]],
|
||||
["months", [2, 8], [-2, -8]],
|
||||
];
|
||||
|
||||
const roundingMode = "expand";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
34
test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfCeil.js
vendored
Normal file
34
test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfCeil.js
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainyearmonth.prototype.since
|
||||
description: Tests calculations with roundingMode "halfCeil".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainYearMonth(2019, 1);
|
||||
const later = new Temporal.PlainYearMonth(2021, 9);
|
||||
|
||||
const expected = [
|
||||
["years", [3], [-3]],
|
||||
["months", [2, 8], [-2, -8]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfCeil";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
34
test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfEven.js
vendored
Normal file
34
test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfEven.js
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainyearmonth.prototype.since
|
||||
description: Tests calculations with roundingMode "halfEven".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainYearMonth(2019, 1);
|
||||
const later = new Temporal.PlainYearMonth(2021, 9);
|
||||
|
||||
const expected = [
|
||||
["years", [3], [-3]],
|
||||
["months", [2, 8], [-2, -8]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfEven";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
34
test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfFloor.js
vendored
Normal file
34
test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfFloor.js
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainyearmonth.prototype.since
|
||||
description: Tests calculations with roundingMode "halfFloor".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainYearMonth(2019, 1);
|
||||
const later = new Temporal.PlainYearMonth(2021, 9);
|
||||
|
||||
const expected = [
|
||||
["years", [3], [-3]],
|
||||
["months", [2, 8], [-2, -8]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfFloor";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
34
test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfTrunc.js
vendored
Normal file
34
test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfTrunc.js
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainyearmonth.prototype.since
|
||||
description: Tests calculations with roundingMode "halfTrunc".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainYearMonth(2019, 1);
|
||||
const later = new Temporal.PlainYearMonth(2021, 9);
|
||||
|
||||
const expected = [
|
||||
["years", [3], [-3]],
|
||||
["months", [2, 8], [-2, -8]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfTrunc";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
34
test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-expand.js
vendored
Normal file
34
test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-expand.js
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainyearmonth.prototype.until
|
||||
description: Tests calculations with roundingMode "expand".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainYearMonth(2019, 1);
|
||||
const later = new Temporal.PlainYearMonth(2021, 9);
|
||||
|
||||
const expected = [
|
||||
["years", [3], [-3]],
|
||||
["months", [2, 8], [-2, -8]],
|
||||
];
|
||||
|
||||
const roundingMode = "expand";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
34
test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfCeil.js
vendored
Normal file
34
test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfCeil.js
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainyearmonth.prototype.until
|
||||
description: Tests calculations with roundingMode "halfCeil".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainYearMonth(2019, 1);
|
||||
const later = new Temporal.PlainYearMonth(2021, 9);
|
||||
|
||||
const expected = [
|
||||
["years", [3], [-3]],
|
||||
["months", [2, 8], [-2, -8]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfCeil";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
34
test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfEven.js
vendored
Normal file
34
test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfEven.js
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainyearmonth.prototype.until
|
||||
description: Tests calculations with roundingMode "halfEven".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainYearMonth(2019, 1);
|
||||
const later = new Temporal.PlainYearMonth(2021, 9);
|
||||
|
||||
const expected = [
|
||||
["years", [3], [-3]],
|
||||
["months", [2, 8], [-2, -8]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfEven";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
34
test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfFloor.js
vendored
Normal file
34
test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfFloor.js
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainyearmonth.prototype.until
|
||||
description: Tests calculations with roundingMode "halfFloor".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainYearMonth(2019, 1);
|
||||
const later = new Temporal.PlainYearMonth(2021, 9);
|
||||
|
||||
const expected = [
|
||||
["years", [3], [-3]],
|
||||
["months", [2, 8], [-2, -8]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfFloor";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
34
test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfTrunc.js
vendored
Normal file
34
test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfTrunc.js
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainyearmonth.prototype.until
|
||||
description: Tests calculations with roundingMode "halfTrunc".
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const earlier = new Temporal.PlainYearMonth(2019, 1);
|
||||
const later = new Temporal.PlainYearMonth(2021, 9);
|
||||
|
||||
const expected = [
|
||||
["years", [3], [-3]],
|
||||
["months", [2, 8], [-2, -8]],
|
||||
];
|
||||
|
||||
const roundingMode = "halfTrunc";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
29
test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingmode-expand.js
vendored
Normal file
29
test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingmode-expand.js
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
// 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.round
|
||||
description: Tests calculations with roundingMode "expand".
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.ZonedDateTime(217175010_123_456_789n /* 1976-11-18T15:23:30.123456789+01:00 */, "+01:00");
|
||||
|
||||
const expected = [
|
||||
["day", 217206000_000_000_000n /* 1976-11-19T00:00:00+01:00 */],
|
||||
["minute", 217175040_000_000_000n /* 1976-11-18T15:24:00+01:00 */],
|
||||
["second", 217175011_000_000_000n /* 1976-11-18T15:23:31+01:00 */],
|
||||
["millisecond", 217175010_124_000_000n /* 1976-11-18T15:23:30.124+01:00 */],
|
||||
["microsecond", 217175010_123_457_000n /* 1976-11-18T15:23:30.123457+01:00 */],
|
||||
["nanosecond", 217175010_123_456_789n /* 1976-11-18T15:23:30.123456789+01:00 */],
|
||||
];
|
||||
|
||||
const roundingMode = "expand";
|
||||
|
||||
expected.forEach(([smallestUnit, expected]) => {
|
||||
assert.sameValue(
|
||||
instance.round({ smallestUnit, roundingMode }).epochNanoseconds,
|
||||
expected,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode})`
|
||||
);
|
||||
});
|
29
test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingmode-halfCeil.js
vendored
Normal file
29
test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingmode-halfCeil.js
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
// 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.round
|
||||
description: Tests calculations with roundingMode "halfCeil".
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.ZonedDateTime(217175010_123_456_789n /* 1976-11-18T15:23:30.123456789+01:00 */, "+01:00");
|
||||
|
||||
const expected = [
|
||||
["day", 217206000_000_000_000n /* 1976-11-19T00:00:00+01:00 */],
|
||||
["minute", 217175040_000_000_000n /* 1976-11-18T15:24:00+01:00 */],
|
||||
["second", 217175010_000_000_000n /* 1976-11-18T15:23:30+01:00 */],
|
||||
["millisecond", 217175010_123_000_000n /* 1976-11-18T15:23:30.123+01:00 */],
|
||||
["microsecond", 217175010_123_457_000n /* 1976-11-18T15:23:30.123457+01:00 */],
|
||||
["nanosecond", 217175010_123_456_789n /* 1976-11-18T15:23:30.123456789+01:00 */],
|
||||
];
|
||||
|
||||
const roundingMode = "halfCeil";
|
||||
|
||||
expected.forEach(([smallestUnit, expected]) => {
|
||||
assert.sameValue(
|
||||
instance.round({ smallestUnit, roundingMode }).epochNanoseconds,
|
||||
expected,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode})`
|
||||
);
|
||||
});
|
29
test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingmode-halfEven.js
vendored
Normal file
29
test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingmode-halfEven.js
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
// 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.round
|
||||
description: Tests calculations with roundingMode "halfEven".
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.ZonedDateTime(217175010_123_456_789n /* 1976-11-18T15:23:30.123456789+01:00 */, "+01:00");
|
||||
|
||||
const expected = [
|
||||
["day", 217206000_000_000_000n /* 1976-11-19T00:00:00+01:00 */],
|
||||
["minute", 217175040_000_000_000n /* 1976-11-18T15:24:00+01:00 */],
|
||||
["second", 217175010_000_000_000n /* 1976-11-18T15:23:30+01:00 */],
|
||||
["millisecond", 217175010_123_000_000n /* 1976-11-18T15:23:30.123+01:00 */],
|
||||
["microsecond", 217175010_123_457_000n /* 1976-11-18T15:23:30.123457+01:00 */],
|
||||
["nanosecond", 217175010_123_456_789n /* 1976-11-18T15:23:30.123456789+01:00 */],
|
||||
];
|
||||
|
||||
const roundingMode = "halfEven";
|
||||
|
||||
expected.forEach(([smallestUnit, expected]) => {
|
||||
assert.sameValue(
|
||||
instance.round({ smallestUnit, roundingMode }).epochNanoseconds,
|
||||
expected,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode})`
|
||||
);
|
||||
});
|
29
test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingmode-halfFloor.js
vendored
Normal file
29
test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingmode-halfFloor.js
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
// 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.round
|
||||
description: Tests calculations with roundingMode "halfFloor".
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.ZonedDateTime(217175010_123_456_789n /* 1976-11-18T15:23:30.123456789+01:00 */, "+01:00");
|
||||
|
||||
const expected = [
|
||||
["day", 217206000_000_000_000n /* 1976-11-19T00:00:00+01:00 */],
|
||||
["minute", 217175040_000_000_000n /* 1976-11-18T15:24:00+01:00 */],
|
||||
["second", 217175010_000_000_000n /* 1976-11-18T15:23:30+01:00 */],
|
||||
["millisecond", 217175010_123_000_000n /* 1976-11-18T15:23:30.123+01:00 */],
|
||||
["microsecond", 217175010_123_457_000n /* 1976-11-18T15:23:30.123457+01:00 */],
|
||||
["nanosecond", 217175010_123_456_789n /* 1976-11-18T15:23:30.123456789+01:00 */],
|
||||
];
|
||||
|
||||
const roundingMode = "halfFloor";
|
||||
|
||||
expected.forEach(([smallestUnit, expected]) => {
|
||||
assert.sameValue(
|
||||
instance.round({ smallestUnit, roundingMode }).epochNanoseconds,
|
||||
expected,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode})`
|
||||
);
|
||||
});
|
29
test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingmode-halfTrunc.js
vendored
Normal file
29
test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingmode-halfTrunc.js
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
// 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.round
|
||||
description: Tests calculations with roundingMode "halfTrunc".
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.ZonedDateTime(217175010_123_456_789n /* 1976-11-18T15:23:30.123456789+01:00 */, "+01:00");
|
||||
|
||||
const expected = [
|
||||
["day", 217206000_000_000_000n /* 1976-11-19T00:00:00+01:00 */],
|
||||
["minute", 217175040_000_000_000n /* 1976-11-18T15:24:00+01:00 */],
|
||||
["second", 217175010_000_000_000n /* 1976-11-18T15:23:30+01:00 */],
|
||||
["millisecond", 217175010_123_000_000n /* 1976-11-18T15:23:30.123+01:00 */],
|
||||
["microsecond", 217175010_123_457_000n /* 1976-11-18T15:23:30.123457+01:00 */],
|
||||
["nanosecond", 217175010_123_456_789n /* 1976-11-18T15:23:30.123456789+01:00 */],
|
||||
];
|
||||
|
||||
const roundingMode = "halfTrunc";
|
||||
|
||||
expected.forEach(([smallestUnit, expected]) => {
|
||||
assert.sameValue(
|
||||
instance.round({ smallestUnit, roundingMode }).epochNanoseconds,
|
||||
expected,
|
||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode})`
|
||||
);
|
||||
});
|
42
test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-expand.js
vendored
Normal file
42
test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-expand.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 "expand".
|
||||
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, 140], [0, 0, -140]],
|
||||
["days", [0, 0, 0, 974], [0, 0, 0, -974]],
|
||||
["hours", [0, 0, 0, 0, 23357], [0, 0, 0, 0, -23357]],
|
||||
["minutes", [0, 0, 0, 0, 23356, 18], [0, 0, 0, 0, -23356, -18]],
|
||||
["seconds", [0, 0, 0, 0, 23356, 17, 5], [0, 0, 0, 0, -23356, -17, -5]],
|
||||
["milliseconds", [0, 0, 0, 0, 23356, 17, 4, 865], [0, 0, 0, 0, -23356, -17, -4, -865]],
|
||||
["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 = "expand";
|
||||
|
||||
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-halfCeil.js
vendored
Normal file
42
test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-halfCeil.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 "halfCeil".
|
||||
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 = "halfCeil";
|
||||
|
||||
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-halfEven.js
vendored
Normal file
42
test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-halfEven.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 "halfEven".
|
||||
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 = "halfEven";
|
||||
|
||||
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-halfFloor.js
vendored
Normal file
42
test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-halfFloor.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 "halfFloor".
|
||||
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 = "halfFloor";
|
||||
|
||||
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-halfTrunc.js
vendored
Normal file
42
test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-halfTrunc.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 "halfTrunc".
|
||||
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 = "halfTrunc";
|
||||
|
||||
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)`
|
||||
);
|
||||
});
|
37
test/built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-expand.js
vendored
Normal file
37
test/built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-expand.js
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// 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.tostring
|
||||
description: expand value for roundingMode option
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const datetime = new Temporal.ZonedDateTime(1_000_000_000_123_987_500n, "UTC");
|
||||
|
||||
const result1 = datetime.toString({ smallestUnit: "microsecond", roundingMode: "expand" });
|
||||
assert.sameValue(result1, "2001-09-09T01:46:40.123988+00:00[UTC]",
|
||||
"roundingMode is expand (with 6 digits from smallestUnit)");
|
||||
|
||||
const result2 = datetime.toString({ fractionalSecondDigits: 6, roundingMode: "expand" });
|
||||
assert.sameValue(result2, "2001-09-09T01:46:40.123988+00:00[UTC]",
|
||||
"roundingMode is expand (with 6 digits from fractionalSecondDigits)");
|
||||
|
||||
const result3 = datetime.toString({ smallestUnit: "millisecond", roundingMode: "expand" });
|
||||
assert.sameValue(result3, "2001-09-09T01:46:40.124+00:00[UTC]",
|
||||
"roundingMode is expand (with 3 digits from smallestUnit)");
|
||||
|
||||
const result4 = datetime.toString({ fractionalSecondDigits: 3, roundingMode: "expand" });
|
||||
assert.sameValue(result4, "2001-09-09T01:46:40.124+00:00[UTC]",
|
||||
"roundingMode is expand (with 3 digits from fractionalSecondDigits)");
|
||||
|
||||
const result5 = datetime.toString({ smallestUnit: "second", roundingMode: "expand" });
|
||||
assert.sameValue(result5, "2001-09-09T01:46:41+00:00[UTC]",
|
||||
"roundingMode is expand (with 0 digits from smallestUnit)");
|
||||
|
||||
const result6 = datetime.toString({ fractionalSecondDigits: 0, roundingMode: "expand" });
|
||||
assert.sameValue(result6, "2001-09-09T01:46:41+00:00[UTC]",
|
||||
"roundingMode is expand (with 0 digits from fractionalSecondDigits)");
|
||||
|
||||
const result7 = datetime.toString({ smallestUnit: "minute", roundingMode: "expand" });
|
||||
assert.sameValue(result7, "2001-09-09T01:47+00:00[UTC]", "roundingMode is expand (round to minute)");
|
37
test/built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-halfCeil.js
vendored
Normal file
37
test/built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-halfCeil.js
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// 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.tostring
|
||||
description: halfCeil value for roundingMode option
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const datetime = new Temporal.ZonedDateTime(1_000_000_000_123_987_500n, "UTC");
|
||||
|
||||
const result1 = datetime.toString({ smallestUnit: "microsecond", roundingMode: "halfCeil" });
|
||||
assert.sameValue(result1, "2001-09-09T01:46:40.123988+00:00[UTC]",
|
||||
"roundingMode is halfCeil (with 6 digits from smallestUnit)");
|
||||
|
||||
const result2 = datetime.toString({ fractionalSecondDigits: 6, roundingMode: "halfCeil" });
|
||||
assert.sameValue(result2, "2001-09-09T01:46:40.123988+00:00[UTC]",
|
||||
"roundingMode is halfCeil (with 6 digits from fractionalSecondDigits)");
|
||||
|
||||
const result3 = datetime.toString({ smallestUnit: "millisecond", roundingMode: "halfCeil" });
|
||||
assert.sameValue(result3, "2001-09-09T01:46:40.124+00:00[UTC]",
|
||||
"roundingMode is halfCeil (with 3 digits from smallestUnit)");
|
||||
|
||||
const result4 = datetime.toString({ fractionalSecondDigits: 3, roundingMode: "halfCeil" });
|
||||
assert.sameValue(result4, "2001-09-09T01:46:40.124+00:00[UTC]",
|
||||
"roundingMode is halfCeil (with 3 digits from fractionalSecondDigits)");
|
||||
|
||||
const result5 = datetime.toString({ smallestUnit: "second", roundingMode: "halfCeil" });
|
||||
assert.sameValue(result5, "2001-09-09T01:46:40+00:00[UTC]",
|
||||
"roundingMode is halfCeil (with 0 digits from smallestUnit)");
|
||||
|
||||
const result6 = datetime.toString({ fractionalSecondDigits: 0, roundingMode: "halfCeil" });
|
||||
assert.sameValue(result6, "2001-09-09T01:46:40+00:00[UTC]",
|
||||
"roundingMode is halfCeil (with 0 digits from fractionalSecondDigits)");
|
||||
|
||||
const result7 = datetime.toString({ smallestUnit: "minute", roundingMode: "halfCeil" });
|
||||
assert.sameValue(result7, "2001-09-09T01:47+00:00[UTC]", "roundingMode is halfCeil (round to minute)");
|
37
test/built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-halfEven.js
vendored
Normal file
37
test/built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-halfEven.js
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// 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.tostring
|
||||
description: halfEven value for roundingMode option
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const datetime = new Temporal.ZonedDateTime(1_000_000_000_123_987_500n, "UTC");
|
||||
|
||||
const result1 = datetime.toString({ smallestUnit: "microsecond", roundingMode: "halfEven" });
|
||||
assert.sameValue(result1, "2001-09-09T01:46:40.123988+00:00[UTC]",
|
||||
"roundingMode is halfEven (with 6 digits from smallestUnit)");
|
||||
|
||||
const result2 = datetime.toString({ fractionalSecondDigits: 6, roundingMode: "halfEven" });
|
||||
assert.sameValue(result2, "2001-09-09T01:46:40.123988+00:00[UTC]",
|
||||
"roundingMode is halfEven (with 6 digits from fractionalSecondDigits)");
|
||||
|
||||
const result3 = datetime.toString({ smallestUnit: "millisecond", roundingMode: "halfEven" });
|
||||
assert.sameValue(result3, "2001-09-09T01:46:40.124+00:00[UTC]",
|
||||
"roundingMode is halfEven (with 3 digits from smallestUnit)");
|
||||
|
||||
const result4 = datetime.toString({ fractionalSecondDigits: 3, roundingMode: "halfEven" });
|
||||
assert.sameValue(result4, "2001-09-09T01:46:40.124+00:00[UTC]",
|
||||
"roundingMode is halfEven (with 3 digits from fractionalSecondDigits)");
|
||||
|
||||
const result5 = datetime.toString({ smallestUnit: "second", roundingMode: "halfEven" });
|
||||
assert.sameValue(result5, "2001-09-09T01:46:40+00:00[UTC]",
|
||||
"roundingMode is halfEven (with 0 digits from smallestUnit)");
|
||||
|
||||
const result6 = datetime.toString({ fractionalSecondDigits: 0, roundingMode: "halfEven" });
|
||||
assert.sameValue(result6, "2001-09-09T01:46:40+00:00[UTC]",
|
||||
"roundingMode is halfEven (with 0 digits from fractionalSecondDigits)");
|
||||
|
||||
const result7 = datetime.toString({ smallestUnit: "minute", roundingMode: "halfEven" });
|
||||
assert.sameValue(result7, "2001-09-09T01:47+00:00[UTC]", "roundingMode is halfEven (round to minute)");
|
37
test/built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-halfFloor.js
vendored
Normal file
37
test/built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-halfFloor.js
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// 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.tostring
|
||||
description: halfFloor value for roundingMode option
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const datetime = new Temporal.ZonedDateTime(1_000_000_000_123_987_500n, "UTC");
|
||||
|
||||
const result1 = datetime.toString({ smallestUnit: "microsecond", roundingMode: "halfFloor" });
|
||||
assert.sameValue(result1, "2001-09-09T01:46:40.123987+00:00[UTC]",
|
||||
"roundingMode is halfFloor (with 6 digits from smallestUnit)");
|
||||
|
||||
const result2 = datetime.toString({ fractionalSecondDigits: 6, roundingMode: "halfFloor" });
|
||||
assert.sameValue(result2, "2001-09-09T01:46:40.123987+00:00[UTC]",
|
||||
"roundingMode is halfFloor (with 6 digits from fractionalSecondDigits)");
|
||||
|
||||
const result3 = datetime.toString({ smallestUnit: "millisecond", roundingMode: "halfFloor" });
|
||||
assert.sameValue(result3, "2001-09-09T01:46:40.124+00:00[UTC]",
|
||||
"roundingMode is halfFloor (with 3 digits from smallestUnit)");
|
||||
|
||||
const result4 = datetime.toString({ fractionalSecondDigits: 3, roundingMode: "halfFloor" });
|
||||
assert.sameValue(result4, "2001-09-09T01:46:40.124+00:00[UTC]",
|
||||
"roundingMode is halfFloor (with 3 digits from fractionalSecondDigits)");
|
||||
|
||||
const result5 = datetime.toString({ smallestUnit: "second", roundingMode: "halfFloor" });
|
||||
assert.sameValue(result5, "2001-09-09T01:46:40+00:00[UTC]",
|
||||
"roundingMode is halfFloor (with 0 digits from smallestUnit)");
|
||||
|
||||
const result6 = datetime.toString({ fractionalSecondDigits: 0, roundingMode: "halfFloor" });
|
||||
assert.sameValue(result6, "2001-09-09T01:46:40+00:00[UTC]",
|
||||
"roundingMode is halfFloor (with 0 digits from fractionalSecondDigits)");
|
||||
|
||||
const result7 = datetime.toString({ smallestUnit: "minute", roundingMode: "halfFloor" });
|
||||
assert.sameValue(result7, "2001-09-09T01:47+00:00[UTC]", "roundingMode is halfFloor (round to minute)");
|
37
test/built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-halfTrunc.js
vendored
Normal file
37
test/built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-halfTrunc.js
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// 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.tostring
|
||||
description: halfTrunc value for roundingMode option
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const datetime = new Temporal.ZonedDateTime(1_000_000_000_123_987_500n, "UTC");
|
||||
|
||||
const result1 = datetime.toString({ smallestUnit: "microsecond", roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result1, "2001-09-09T01:46:40.123987+00:00[UTC]",
|
||||
"roundingMode is halfTrunc (with 6 digits from smallestUnit)");
|
||||
|
||||
const result2 = datetime.toString({ fractionalSecondDigits: 6, roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result2, "2001-09-09T01:46:40.123987+00:00[UTC]",
|
||||
"roundingMode is halfTrunc (with 6 digits from fractionalSecondDigits)");
|
||||
|
||||
const result3 = datetime.toString({ smallestUnit: "millisecond", roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result3, "2001-09-09T01:46:40.124+00:00[UTC]",
|
||||
"roundingMode is halfTrunc (with 3 digits from smallestUnit)");
|
||||
|
||||
const result4 = datetime.toString({ fractionalSecondDigits: 3, roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result4, "2001-09-09T01:46:40.124+00:00[UTC]",
|
||||
"roundingMode is halfTrunc (with 3 digits from fractionalSecondDigits)");
|
||||
|
||||
const result5 = datetime.toString({ smallestUnit: "second", roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result5, "2001-09-09T01:46:40+00:00[UTC]",
|
||||
"roundingMode is halfTrunc (with 0 digits from smallestUnit)");
|
||||
|
||||
const result6 = datetime.toString({ fractionalSecondDigits: 0, roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result6, "2001-09-09T01:46:40+00:00[UTC]",
|
||||
"roundingMode is halfTrunc (with 0 digits from fractionalSecondDigits)");
|
||||
|
||||
const result7 = datetime.toString({ smallestUnit: "minute", roundingMode: "halfTrunc" });
|
||||
assert.sameValue(result7, "2001-09-09T01:47+00:00[UTC]", "roundingMode is halfTrunc (round to minute)");
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user