mirror of
https://github.com/tc39/test262.git
synced 2025-07-26 23:44:27 +02:00
Temporal: Move tests for ZonedDateTime/p/{since, until} out of staging (#4293)
Co-authored-by: Philip Chimento <philip.chimento@gmail.com>
This commit is contained in:
parent
ccf8977b1c
commit
b7822bb0b8
29
test/built-ins/Temporal/ZonedDateTime/prototype/since/can-return-lower-or-higher-units.js
vendored
Normal file
29
test/built-ins/Temporal/ZonedDateTime/prototype/since/can-return-lower-or-higher-units.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.since
|
||||||
|
description: Can return lower or higher units.
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
const feb20 = Temporal.ZonedDateTime.from("2020-02-01T00:00+01:00[+01:00]");
|
||||||
|
const feb21 = Temporal.ZonedDateTime.from("2021-02-01T00:00+01:00[+01:00]");
|
||||||
|
*/
|
||||||
|
const feb20 = new Temporal.ZonedDateTime(1580511600000000000n, "+01:00");
|
||||||
|
const feb21 = new Temporal.ZonedDateTime(1612134000000000000n, "+01:00");
|
||||||
|
|
||||||
|
TemporalHelpers.assertDuration(feb21.since(feb20, { largestUnit: "years" }),
|
||||||
|
1, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(feb21.since(feb20, { largestUnit: "months" }),
|
||||||
|
0, 12, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(feb21.since(feb20, { largestUnit: "weeks" }),
|
||||||
|
0, 0, 52, 2, 0, 0, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(feb21.since(feb20, { largestUnit: "days" }),
|
||||||
|
0, 0, 0, 366, 0, 0, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(feb21.since(feb20, { largestUnit: "minutes" }),
|
||||||
|
0, 0, 0, 0, 0, 527040, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(feb21.since(feb20, { largestUnit: "seconds" }),
|
||||||
|
0, 0, 0, 0, 0, 0, 31622400, 0, 0, 0);
|
28
test/built-ins/Temporal/ZonedDateTime/prototype/since/casts-argument.js
vendored
Normal file
28
test/built-ins/Temporal/ZonedDateTime/prototype/since/casts-argument.js
vendored
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.since
|
||||||
|
description: since() casts argument from object or string.
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// var zdt = Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789+01:00[+01:00]");
|
||||||
|
const zdt = new Temporal.ZonedDateTime(217175010123456789n, "+01:00");
|
||||||
|
// "2019-10-29T10:46:38.271986102+01:00[+01:00]"
|
||||||
|
const zdt2 = new Temporal.ZonedDateTime(1572342398271986102n, "+01:00");
|
||||||
|
|
||||||
|
TemporalHelpers.assertDuration(zdt.since({
|
||||||
|
year: 2019,
|
||||||
|
month: 10,
|
||||||
|
day: 29,
|
||||||
|
hour: 10,
|
||||||
|
timeZone: "+01:00"
|
||||||
|
}), 0, 0, 0, 0, -376434, -36, -29, -876, -543, -211);
|
||||||
|
TemporalHelpers.assertDuration(zdt.since(zdt2),
|
||||||
|
0, 0, 0, 0, -376435, -23, -8, -148, -529, -313);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
37
test/built-ins/Temporal/ZonedDateTime/prototype/since/defaults-to-returning-hours.js
vendored
Normal file
37
test/built-ins/Temporal/ZonedDateTime/prototype/since/defaults-to-returning-hours.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.since
|
||||||
|
description: Defaults to returning hours.
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
const feb20 = Temporal.ZonedDateTime.from("2020-02-01T00:00+01:00[+01:00]");
|
||||||
|
const feb21 = Temporal.ZonedDateTime.from("2021-02-01T00:00+01:00[+01:00]");
|
||||||
|
*/
|
||||||
|
const feb20 = new Temporal.ZonedDateTime(1580511600000000000n, "+01:00");
|
||||||
|
const feb21 = new Temporal.ZonedDateTime(1612134000000000000n, "+01:00");
|
||||||
|
// "2021-02-01T00:00:00.000000001+01:00[+01:00]"
|
||||||
|
const feb1_2021 = new Temporal.ZonedDateTime(1612134000000000001n, "+01:00");
|
||||||
|
// "2020-02-01T00:00:00.000000001+01:00[+01:00]"
|
||||||
|
const feb1_2020 = new Temporal.ZonedDateTime(1580511600000000001n, "+01:00");
|
||||||
|
|
||||||
|
TemporalHelpers.assertDuration(
|
||||||
|
feb21.since(feb20),
|
||||||
|
0, 0, 0, 0, 8784, 0, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(
|
||||||
|
feb21.since(feb20, { largestUnit: "auto" }),
|
||||||
|
0, 0, 0, 0, 8784, 0, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(
|
||||||
|
feb21.since(feb20, { largestUnit: "hours" }),
|
||||||
|
0, 0, 0, 0, 8784, 0, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(
|
||||||
|
feb1_2021.since(feb20),
|
||||||
|
0, 0, 0, 0, 8784, 0, 0, 0, 0, 1);
|
||||||
|
TemporalHelpers.assertDuration(
|
||||||
|
feb21.since(feb1_2020),
|
||||||
|
0, 0, 0, 0, 8783, 59, 59, 999, 999, 999);
|
||||||
|
|
@ -0,0 +1,23 @@
|
|||||||
|
// 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: Does not include higher units than necessary in the return value.
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
const lastFeb20 = Temporal.ZonedDateTime.from("2020-02-29T00:00+01:00[+01:00]");
|
||||||
|
const lastFeb21 = Temporal.ZonedDateTime.from("2021-02-28T00:00+01:00[+01:00]");
|
||||||
|
*/
|
||||||
|
const lastFeb20 = new Temporal.ZonedDateTime(1582930800000000000n, "+01:00");
|
||||||
|
const lastFeb21 = new Temporal.ZonedDateTime(1614466800000000000n, "+01:00");
|
||||||
|
|
||||||
|
TemporalHelpers.assertDuration(lastFeb21.since(lastFeb20),
|
||||||
|
0, 0, 0, 0, 8760, 0, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(lastFeb21.since(lastFeb20, { largestUnit: "months" }),
|
||||||
|
0, 11, 0, 28, 0, 0, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(lastFeb21.since(lastFeb20, { largestUnit: "years" }),
|
||||||
|
0, 11, 0, 28, 0, 0, 0, 0, 0, 0);
|
67
test/built-ins/Temporal/ZonedDateTime/prototype/since/invalid-rounding-increments.js
vendored
Normal file
67
test/built-ins/Temporal/ZonedDateTime/prototype/since/invalid-rounding-increments.js
vendored
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
// 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: Rounds to various increments.
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
const earlier = Temporal.ZonedDateTime.from('2019-01-08T09:22:36.123456789+01:00[+01:00]');
|
||||||
|
const later = Temporal.ZonedDateTime.from('2021-09-07T13:39:40.987654321+01:00[+01:00]');
|
||||||
|
*/
|
||||||
|
const earlier = new Temporal.ZonedDateTime(1546935756123456789n, "+01:00");
|
||||||
|
const later = new Temporal.ZonedDateTime(1631018380987654321n, "+01:00");
|
||||||
|
|
||||||
|
// throws on increments that do not divide evenly into the next highest
|
||||||
|
assert.throws(RangeError, () => later.since(earlier, {
|
||||||
|
smallestUnit: "hours",
|
||||||
|
roundingIncrement: 11
|
||||||
|
}));
|
||||||
|
assert.throws(RangeError, () => later.since(earlier, {
|
||||||
|
smallestUnit: "minutes",
|
||||||
|
roundingIncrement: 29
|
||||||
|
}));
|
||||||
|
assert.throws(RangeError, () => later.since(earlier, {
|
||||||
|
smallestUnit: "seconds",
|
||||||
|
roundingIncrement: 29
|
||||||
|
}));
|
||||||
|
assert.throws(RangeError, () => later.since(earlier, {
|
||||||
|
smallestUnit: "milliseconds",
|
||||||
|
roundingIncrement: 29
|
||||||
|
}));
|
||||||
|
assert.throws(RangeError, () => later.since(earlier, {
|
||||||
|
smallestUnit: "microseconds",
|
||||||
|
roundingIncrement: 29
|
||||||
|
}));
|
||||||
|
assert.throws(RangeError, () => later.since(earlier, {
|
||||||
|
smallestUnit: "nanoseconds",
|
||||||
|
roundingIncrement: 29
|
||||||
|
}));
|
||||||
|
|
||||||
|
// throws on increments that are equal to the next highest
|
||||||
|
assert.throws(RangeError, () => later.since(earlier, {
|
||||||
|
smallestUnit: "hours",
|
||||||
|
roundingIncrement: 24
|
||||||
|
}));
|
||||||
|
assert.throws(RangeError, () => later.since(earlier, {
|
||||||
|
smallestUnit: "minutes",
|
||||||
|
roundingIncrement: 60
|
||||||
|
}));
|
||||||
|
assert.throws(RangeError, () => later.since(earlier, {
|
||||||
|
smallestUnit: "seconds",
|
||||||
|
roundingIncrement: 60
|
||||||
|
}));
|
||||||
|
assert.throws(RangeError, () => later.since(earlier, {
|
||||||
|
smallestUnit: "milliseconds",
|
||||||
|
roundingIncrement: 1000
|
||||||
|
}));
|
||||||
|
assert.throws(RangeError, () => later.since(earlier, {
|
||||||
|
smallestUnit: "microseconds",
|
||||||
|
roundingIncrement: 1000
|
||||||
|
}));
|
||||||
|
assert.throws(RangeError, () => later.since(earlier, {
|
||||||
|
smallestUnit: "nanoseconds",
|
||||||
|
roundingIncrement: 1000
|
||||||
|
}));
|
31
test/built-ins/Temporal/ZonedDateTime/prototype/since/largestunit-default.js
vendored
Normal file
31
test/built-ins/Temporal/ZonedDateTime/prototype/since/largestunit-default.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.zoneddatetime.prototype.since
|
||||||
|
description: Assumes a different default for largestUnit if smallestUnit is larger than days
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
const earlier = Temporal.ZonedDateTime.from('2019-01-08T09:22:36.123456789+01:00[+01:00]');
|
||||||
|
const later = Temporal.ZonedDateTime.from('2021-09-07T13:39:40.987654321+01:00[+01:00]');
|
||||||
|
*/
|
||||||
|
const earlier = new Temporal.ZonedDateTime(1546935756123456789n, "+01:00");
|
||||||
|
const later = new Temporal.ZonedDateTime(1631018380987654321n, "+01:00");
|
||||||
|
|
||||||
|
TemporalHelpers.assertDuration(later.since(earlier, {
|
||||||
|
smallestUnit: "years",
|
||||||
|
roundingMode: "halfExpand"
|
||||||
|
}), 3, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(later.since(earlier, {
|
||||||
|
smallestUnit: "months",
|
||||||
|
roundingMode: "halfExpand"
|
||||||
|
}), 0, 32, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(later.since(earlier, {
|
||||||
|
smallestUnit: "weeks",
|
||||||
|
roundingMode: "halfExpand"
|
||||||
|
}), 0, 0, 139, 0, 0, 0, 0, 0, 0, 0);
|
||||||
|
|
||||||
|
|
58
test/built-ins/Temporal/ZonedDateTime/prototype/since/rounding-increments.js
vendored
Normal file
58
test/built-ins/Temporal/ZonedDateTime/prototype/since/rounding-increments.js
vendored
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
// 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: Rounds to various increments.
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
const earlier = Temporal.ZonedDateTime.from('2019-01-08T09:22:36.123456789+01:00[+01:00]');
|
||||||
|
const later = Temporal.ZonedDateTime.from('2021-09-07T13:39:40.987654321+01:00[+01:00]');
|
||||||
|
*/
|
||||||
|
const earlier = new Temporal.ZonedDateTime(1546935756123456789n, "+01:00");
|
||||||
|
const later = new Temporal.ZonedDateTime(1631018380987654321n, "+01:00");
|
||||||
|
|
||||||
|
// rounds to an increment of hours
|
||||||
|
TemporalHelpers.assertDuration(later.since(earlier, {
|
||||||
|
smallestUnit: "hours",
|
||||||
|
roundingIncrement: 3,
|
||||||
|
roundingMode: "halfExpand"
|
||||||
|
}), 0, 0, 0, 0, 23355, 0, 0, 0, 0, 0);
|
||||||
|
|
||||||
|
// rounds to an increment of minutes
|
||||||
|
TemporalHelpers.assertDuration(later.since(earlier, {
|
||||||
|
smallestUnit: "minutes",
|
||||||
|
roundingIncrement: 30,
|
||||||
|
roundingMode: "halfExpand"
|
||||||
|
}), 0, 0, 0, 0, 23356, 30, 0, 0, 0, 0);
|
||||||
|
|
||||||
|
// rounds to an increment of seconds
|
||||||
|
TemporalHelpers.assertDuration(later.since(earlier, {
|
||||||
|
smallestUnit: "seconds",
|
||||||
|
roundingIncrement: 15,
|
||||||
|
roundingMode: "halfExpand"
|
||||||
|
}), 0, 0, 0, 0, 23356, 17, 0, 0, 0, 0);
|
||||||
|
|
||||||
|
// rounds to an increment of milliseconds
|
||||||
|
TemporalHelpers.assertDuration(later.since(earlier, {
|
||||||
|
smallestUnit: "milliseconds",
|
||||||
|
roundingIncrement: 10,
|
||||||
|
roundingMode: "halfExpand"
|
||||||
|
}), 0, 0, 0, 0, 23356, 17, 4, 860, 0, 0);
|
||||||
|
|
||||||
|
// rounds to an increment of microseconds
|
||||||
|
TemporalHelpers.assertDuration(later.since(earlier, {
|
||||||
|
smallestUnit: "microseconds",
|
||||||
|
roundingIncrement: 10,
|
||||||
|
roundingMode: "halfExpand"
|
||||||
|
}), 0, 0, 0, 0, 23356, 17, 4, 864, 200, 0);
|
||||||
|
|
||||||
|
// rounds to an increment of nanoseconds
|
||||||
|
TemporalHelpers.assertDuration(later.since(earlier, {
|
||||||
|
smallestUnit: "nanoseconds",
|
||||||
|
roundingIncrement: 10,
|
||||||
|
roundingMode: "halfExpand"
|
||||||
|
}), 0, 0, 0, 0, 23356, 17, 4, 864, 197, 530);
|
26
test/built-ins/Temporal/ZonedDateTime/prototype/since/rounds-relative-to-receiver.js
vendored
Normal file
26
test/built-ins/Temporal/ZonedDateTime/prototype/since/rounds-relative-to-receiver.js
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// 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: Rounds relative to the receiver.
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// rounds relative to the receiver
|
||||||
|
/*
|
||||||
|
const dt1 = Temporal.ZonedDateTime.from("2019-01-01T00:00+00:00[UTC]");
|
||||||
|
const dt2 = Temporal.ZonedDateTime.from("2020-07-02T00:00+00:00[UTC]");
|
||||||
|
*/
|
||||||
|
const dt1 = new Temporal.ZonedDateTime(1546300800000000000n, "UTC");
|
||||||
|
const dt2 = new Temporal.ZonedDateTime(1593648000000000000n, "UTC");
|
||||||
|
|
||||||
|
TemporalHelpers.assertDuration(dt2.since(dt1, {
|
||||||
|
smallestUnit: "years",
|
||||||
|
roundingMode: "halfExpand"
|
||||||
|
}), 1, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(dt1.since(dt2, {
|
||||||
|
smallestUnit: "years",
|
||||||
|
roundingMode: "halfExpand"
|
||||||
|
}), -2, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
17
test/built-ins/Temporal/ZonedDateTime/prototype/since/since-until.js
vendored
Normal file
17
test/built-ins/Temporal/ZonedDateTime/prototype/since/since-until.js
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// 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: zdt.since(earlier) == earlier.until(zdt) with default options.
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// var zdt = Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789+01:00[+01:00]");
|
||||||
|
const zdt = new Temporal.ZonedDateTime(217175010123456789n, "+01:00");
|
||||||
|
const earlier = new Temporal.ZonedDateTime(-120898800000000000n, "+01:00");
|
||||||
|
|
||||||
|
TemporalHelpers.assertDurationsEqual(zdt.since(earlier), earlier.until(zdt));
|
||||||
|
|
||||||
|
|
32
test/built-ins/Temporal/ZonedDateTime/prototype/since/subseconds.js
vendored
Normal file
32
test/built-ins/Temporal/ZonedDateTime/prototype/since/subseconds.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.zoneddatetime.prototype.since
|
||||||
|
description: Can return subseconds.
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
const feb20 = Temporal.ZonedDateTime.from("2020-02-01T00:00+01:00[+01:00]");
|
||||||
|
*/
|
||||||
|
const feb20 = new Temporal.ZonedDateTime(1580511600000000000n, "+01:00");
|
||||||
|
const later = feb20.add({
|
||||||
|
days: 1,
|
||||||
|
milliseconds: 250,
|
||||||
|
microseconds: 250,
|
||||||
|
nanoseconds: 250
|
||||||
|
});
|
||||||
|
|
||||||
|
const msDiff = later.since(feb20, { largestUnit: "milliseconds" });
|
||||||
|
TemporalHelpers.assertDuration(msDiff,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 86400250, 250, 250);
|
||||||
|
|
||||||
|
const µsDiff = later.since(feb20, { largestUnit: "microseconds" });
|
||||||
|
TemporalHelpers.assertDuration(µsDiff,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 86400250250, 250);
|
||||||
|
|
||||||
|
const nsDiff = later.since(feb20, { largestUnit: "nanoseconds" });
|
||||||
|
TemporalHelpers.assertDuration(nsDiff,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 86400250250250);
|
85
test/built-ins/Temporal/ZonedDateTime/prototype/since/valid-rounding-increments.js
vendored
Normal file
85
test/built-ins/Temporal/ZonedDateTime/prototype/since/valid-rounding-increments.js
vendored
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
// 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: Valid rounding increments (based on divisibility).
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
const earlier = Temporal.ZonedDateTime.from('2019-01-08T09:22:36.123456789+01:00[+01:00]');
|
||||||
|
const later = Temporal.ZonedDateTime.from('2021-09-07T13:39:40.987654321+01:00[+01:00]');
|
||||||
|
*/
|
||||||
|
const earlier = new Temporal.ZonedDateTime(1546935756123456789n, "+01:00");
|
||||||
|
const later = new Temporal.ZonedDateTime(1631018380987654321n, "+01:00");
|
||||||
|
|
||||||
|
// valid hour increments divide into 24
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
6,
|
||||||
|
8,
|
||||||
|
12
|
||||||
|
].forEach(roundingIncrement => {
|
||||||
|
const options = {
|
||||||
|
smallestUnit: "hours",
|
||||||
|
roundingIncrement
|
||||||
|
};
|
||||||
|
assert(later.since(earlier, options) instanceof Temporal.Duration);
|
||||||
|
});
|
||||||
|
[
|
||||||
|
"minutes",
|
||||||
|
"seconds"
|
||||||
|
].forEach(smallestUnit => {
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
5,
|
||||||
|
6,
|
||||||
|
10,
|
||||||
|
12,
|
||||||
|
15,
|
||||||
|
20,
|
||||||
|
30
|
||||||
|
].forEach(roundingIncrement => {
|
||||||
|
const options = {
|
||||||
|
smallestUnit,
|
||||||
|
roundingIncrement
|
||||||
|
};
|
||||||
|
assert(later.since(earlier, options) instanceof Temporal.Duration);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
[
|
||||||
|
"milliseconds",
|
||||||
|
"microseconds",
|
||||||
|
"nanoseconds"
|
||||||
|
].forEach(smallestUnit => {
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
5,
|
||||||
|
8,
|
||||||
|
10,
|
||||||
|
20,
|
||||||
|
25,
|
||||||
|
40,
|
||||||
|
50,
|
||||||
|
100,
|
||||||
|
125,
|
||||||
|
200,
|
||||||
|
250,
|
||||||
|
500
|
||||||
|
].forEach(roundingIncrement => {
|
||||||
|
const options = {
|
||||||
|
smallestUnit,
|
||||||
|
roundingIncrement
|
||||||
|
};
|
||||||
|
assert(later.since(earlier, options) instanceof Temporal.Duration);
|
||||||
|
});
|
||||||
|
});
|
20
test/built-ins/Temporal/ZonedDateTime/prototype/since/weeks-and-months-are-mutually-exclusive.js
vendored
Normal file
20
test/built-ins/Temporal/ZonedDateTime/prototype/since/weeks-and-months-are-mutually-exclusive.js
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// 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: Weeks and months are mutually exclusive.
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// var zdt = Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789+01:00[+01:00]");
|
||||||
|
const zdt = new Temporal.ZonedDateTime(217175010123456789n, "+01:00");
|
||||||
|
const laterDateTime = zdt.add({ days: 42, hours: 3});
|
||||||
|
|
||||||
|
const weeksDifference = laterDateTime.since(zdt, { largestUnit: "weeks" });
|
||||||
|
assert.notSameValue(weeksDifference.weeks, 0);
|
||||||
|
assert.sameValue(weeksDifference.months, 0);
|
||||||
|
|
||||||
|
const monthsDifference = laterDateTime.since(zdt, { largestUnit: "months" });
|
||||||
|
assert.sameValue(monthsDifference.weeks, 0);
|
||||||
|
assert.notSameValue(monthsDifference.months, 0);
|
31
test/built-ins/Temporal/ZonedDateTime/prototype/until/can-return-lower-or-higher-units.js
vendored
Normal file
31
test/built-ins/Temporal/ZonedDateTime/prototype/until/can-return-lower-or-higher-units.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.zoneddatetime.prototype.until
|
||||||
|
description: Can return lower or higher units.
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const feb20 = Temporal.ZonedDateTime.from("2020-02-01T00:00+01:00[+01:00]");
|
||||||
|
const feb21 = Temporal.ZonedDateTime.from("2021-02-01T00:00+01:00[+01:00]");
|
||||||
|
|
||||||
|
TemporalHelpers.assertDuration(
|
||||||
|
feb20.until(feb21, { largestUnit: "years" }),
|
||||||
|
1, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(
|
||||||
|
feb20.until(feb21, { largestUnit: "months" }),
|
||||||
|
0, 12, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(
|
||||||
|
feb20.until(feb21, { largestUnit: "weeks" }),
|
||||||
|
0, 0, 52, 2, 0, 0, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(
|
||||||
|
feb20.until(feb21, { largestUnit: "days" }),
|
||||||
|
0, 0, 0, 366, 0, 0, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(
|
||||||
|
feb20.until(feb21, { largestUnit: "minutes" }),
|
||||||
|
0, 0, 0, 0, 0, 527040, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(
|
||||||
|
feb20.until(feb21, { largestUnit: "seconds" }),
|
||||||
|
0, 0, 0, 0, 0, 0, 31622400, 0, 0, 0);
|
25
test/built-ins/Temporal/ZonedDateTime/prototype/until/casts-argument.js
vendored
Normal file
25
test/built-ins/Temporal/ZonedDateTime/prototype/until/casts-argument.js
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.until
|
||||||
|
description: until() casts its argument to a ZonedDateTime.
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const zdt = Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789+01:00[+01:00]");
|
||||||
|
|
||||||
|
TemporalHelpers.assertDuration(
|
||||||
|
zdt.until({
|
||||||
|
year: 2019,
|
||||||
|
month: 10,
|
||||||
|
day: 29,
|
||||||
|
hour: 10,
|
||||||
|
timeZone: "+01:00"
|
||||||
|
}), 0, 0, 0, 0, 376434, 36, 29, 876, 543, 211);
|
||||||
|
|
||||||
|
TemporalHelpers.assertDuration(
|
||||||
|
zdt.until("2019-10-29T10:46:38.271986102+01:00[+01:00]"),
|
||||||
|
0, 0, 0, 0, 376435, 23, 8, 148, 529, 313);
|
||||||
|
|
28
test/built-ins/Temporal/ZonedDateTime/prototype/until/defaults-to-returning-hours.js
vendored
Normal file
28
test/built-ins/Temporal/ZonedDateTime/prototype/until/defaults-to-returning-hours.js
vendored
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.until
|
||||||
|
description: Defaults to returning hours.
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const feb20 = Temporal.ZonedDateTime.from("2020-02-01T00:00+01:00[+01:00]");
|
||||||
|
const feb21 = Temporal.ZonedDateTime.from("2021-02-01T00:00+01:00[+01:00]");
|
||||||
|
|
||||||
|
TemporalHelpers.assertDuration(
|
||||||
|
feb20.until(feb21),
|
||||||
|
0, 0, 0, 0, 8784, 0, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(
|
||||||
|
feb20.until(feb21, { largestUnit: "auto" }),
|
||||||
|
0, 0, 0, 0, 8784, 0, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(
|
||||||
|
feb20.until(feb21, { largestUnit: "hours" }),
|
||||||
|
0, 0, 0, 0, 8784, 0, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(
|
||||||
|
feb20.until(Temporal.ZonedDateTime.from("2021-02-01T00:00:00.000000001+01:00[+01:00]")),
|
||||||
|
0, 0, 0, 0, 8784, 0, 0, 0, 0, 1);
|
||||||
|
TemporalHelpers.assertDuration(
|
||||||
|
Temporal.ZonedDateTime.from("2020-02-01T00:00:00.000000001+01:00[+01:00]").until(feb21),
|
||||||
|
0, 0, 0, 0, 8783, 59, 59, 999, 999, 999);
|
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.until
|
||||||
|
description: Does not include higher units than necessary in the return value.
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const lastFeb20 = Temporal.ZonedDateTime.from("2020-02-29T00:00+01:00[+01:00]");
|
||||||
|
const lastJan21 = Temporal.ZonedDateTime.from("2021-01-31T00:00+01:00[+01:00]");
|
||||||
|
|
||||||
|
TemporalHelpers.assertDuration(lastFeb20.until(lastJan21),
|
||||||
|
0, 0, 0, 0, 8088, 0, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(lastFeb20.until(lastJan21, { largestUnit: "months" }),
|
||||||
|
0, 11, 0, 2, 0, 0, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(lastFeb20.until(lastJan21, { largestUnit: "years" }),
|
||||||
|
0, 11, 0, 2, 0, 0, 0, 0, 0, 0);
|
63
test/built-ins/Temporal/ZonedDateTime/prototype/until/invalid-increments.js
vendored
Normal file
63
test/built-ins/Temporal/ZonedDateTime/prototype/until/invalid-increments.js
vendored
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.until
|
||||||
|
description: Throws on invalid increments.
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const earlier = new Temporal.ZonedDateTime(0n, "+01:00");
|
||||||
|
const later = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "+01:00");
|
||||||
|
|
||||||
|
// throws on increments that do not divide evenly into the next highest
|
||||||
|
assert.throws(RangeError, () => earlier.until(later, {
|
||||||
|
smallestUnit: "hours",
|
||||||
|
roundingIncrement: 11
|
||||||
|
}));
|
||||||
|
assert.throws(RangeError, () => earlier.until(later, {
|
||||||
|
smallestUnit: "minutes",
|
||||||
|
roundingIncrement: 29
|
||||||
|
}));
|
||||||
|
assert.throws(RangeError, () => earlier.until(later, {
|
||||||
|
smallestUnit: "seconds",
|
||||||
|
roundingIncrement: 29
|
||||||
|
}));
|
||||||
|
assert.throws(RangeError, () => earlier.until(later, {
|
||||||
|
smallestUnit: "milliseconds",
|
||||||
|
roundingIncrement: 29
|
||||||
|
}));
|
||||||
|
assert.throws(RangeError, () => earlier.until(later, {
|
||||||
|
smallestUnit: "microseconds",
|
||||||
|
roundingIncrement: 29
|
||||||
|
}));
|
||||||
|
assert.throws(RangeError, () => earlier.until(later, {
|
||||||
|
smallestUnit: "nanoseconds",
|
||||||
|
roundingIncrement: 29
|
||||||
|
}));
|
||||||
|
|
||||||
|
// throws on increments that are equal to the next highest
|
||||||
|
assert.throws(RangeError, () => earlier.until(later, {
|
||||||
|
smallestUnit: "hours",
|
||||||
|
roundingIncrement: 24
|
||||||
|
}));
|
||||||
|
assert.throws(RangeError, () => earlier.until(later, {
|
||||||
|
smallestUnit: "minutes",
|
||||||
|
roundingIncrement: 60
|
||||||
|
}));
|
||||||
|
assert.throws(RangeError, () => earlier.until(later, {
|
||||||
|
smallestUnit: "seconds",
|
||||||
|
roundingIncrement: 60
|
||||||
|
}));
|
||||||
|
assert.throws(RangeError, () => earlier.until(later, {
|
||||||
|
smallestUnit: "milliseconds",
|
||||||
|
roundingIncrement: 1000
|
||||||
|
}));
|
||||||
|
assert.throws(RangeError, () => earlier.until(later, {
|
||||||
|
smallestUnit: "microseconds",
|
||||||
|
roundingIncrement: 1000
|
||||||
|
}));
|
||||||
|
assert.throws(RangeError, () => earlier.until(later, {
|
||||||
|
smallestUnit: "nanoseconds",
|
||||||
|
roundingIncrement: 1000
|
||||||
|
}));
|
29
test/built-ins/Temporal/ZonedDateTime/prototype/until/largestunit-default.js
vendored
Normal file
29
test/built-ins/Temporal/ZonedDateTime/prototype/until/largestunit-default.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.until
|
||||||
|
description: Assumes a different default for largestUnit if smallestUnit is larger than hours.
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const earlier = Temporal.ZonedDateTime.from('2019-01-08T09:22:36.123456789+01:00[+01:00]');
|
||||||
|
const later = Temporal.ZonedDateTime.from('2021-09-07T13:39:40.987654321+01:00[+01:00]');
|
||||||
|
|
||||||
|
TemporalHelpers.assertDuration(earlier.until(later, {
|
||||||
|
smallestUnit: "years",
|
||||||
|
roundingMode: "halfExpand"
|
||||||
|
}), 3, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(earlier.until(later, {
|
||||||
|
smallestUnit: "months",
|
||||||
|
roundingMode: "halfExpand"
|
||||||
|
}), 0, 32, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(earlier.until(later, {
|
||||||
|
smallestUnit: "weeks",
|
||||||
|
roundingMode: "halfExpand"
|
||||||
|
}), 0, 0, 139, 0, 0, 0, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(earlier.until(later, {
|
||||||
|
smallestUnit: "days",
|
||||||
|
roundingMode: "halfExpand"
|
||||||
|
}), 0, 0, 0, 973, 0, 0, 0, 0, 0, 0);
|
54
test/built-ins/Temporal/ZonedDateTime/prototype/until/rounding-increments.js
vendored
Normal file
54
test/built-ins/Temporal/ZonedDateTime/prototype/until/rounding-increments.js
vendored
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.until
|
||||||
|
description: until() can round to various increments.
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const earlier = Temporal.ZonedDateTime.from('2019-01-08T09:22:36.123456789+01:00[+01:00]');
|
||||||
|
const later = Temporal.ZonedDateTime.from('2021-09-07T13:39:40.987654321+01:00[+01:00]');
|
||||||
|
|
||||||
|
// rounds to an increment of hours
|
||||||
|
TemporalHelpers.assertDuration(earlier.until(later, {
|
||||||
|
smallestUnit: "hours",
|
||||||
|
roundingIncrement: 3,
|
||||||
|
roundingMode: "halfExpand"
|
||||||
|
}), 0, 0, 0, 0, 23355, 0, 0, 0, 0, 0);
|
||||||
|
|
||||||
|
// rounds to an increment of minutes
|
||||||
|
TemporalHelpers.assertDuration(earlier.until(later, {
|
||||||
|
smallestUnit: "minutes",
|
||||||
|
roundingIncrement: 30,
|
||||||
|
roundingMode: "halfExpand"
|
||||||
|
}), 0, 0, 0, 0, 23356, 30, 0, 0, 0, 0);
|
||||||
|
|
||||||
|
// rounds to an increment of seconds
|
||||||
|
TemporalHelpers.assertDuration(earlier.until(later, {
|
||||||
|
smallestUnit: "seconds",
|
||||||
|
roundingIncrement: 15,
|
||||||
|
roundingMode: "halfExpand"
|
||||||
|
}), 0, 0, 0, 0, 23356, 17, 0, 0, 0, 0);
|
||||||
|
|
||||||
|
// rounds to an increment of milliseconds
|
||||||
|
TemporalHelpers.assertDuration(earlier.until(later, {
|
||||||
|
smallestUnit: "milliseconds",
|
||||||
|
roundingIncrement: 10,
|
||||||
|
roundingMode: "halfExpand"
|
||||||
|
}), 0, 0, 0, 0, 23356, 17, 4, 860, 0, 0);
|
||||||
|
|
||||||
|
// rounds to an increment of microseconds
|
||||||
|
TemporalHelpers.assertDuration(earlier.until(later, {
|
||||||
|
smallestUnit: "microseconds",
|
||||||
|
roundingIncrement: 10,
|
||||||
|
roundingMode: "halfExpand"
|
||||||
|
}), 0, 0, 0, 0, 23356, 17, 4, 864, 200, 0);
|
||||||
|
|
||||||
|
// rounds to an increment of nanoseconds
|
||||||
|
TemporalHelpers.assertDuration(earlier.until(later, {
|
||||||
|
smallestUnit: "nanoseconds",
|
||||||
|
roundingIncrement: 10,
|
||||||
|
roundingMode: "halfExpand"
|
||||||
|
}), 0, 0, 0, 0, 23356, 17, 4, 864, 197, 530);
|
23
test/built-ins/Temporal/ZonedDateTime/prototype/until/rounds-relative-to-receiver.js
vendored
Normal file
23
test/built-ins/Temporal/ZonedDateTime/prototype/until/rounds-relative-to-receiver.js
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.until
|
||||||
|
description: Rounds relative to the receiver.
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
|
||||||
|
// rounds relative to the receiver
|
||||||
|
const dt1 = Temporal.ZonedDateTime.from("2019-01-01T00:00+00:00[UTC]");
|
||||||
|
const dt2 = Temporal.ZonedDateTime.from("2020-07-02T00:00+00:00[UTC]");
|
||||||
|
TemporalHelpers.assertDuration(dt1.until(dt2, {
|
||||||
|
smallestUnit: "years",
|
||||||
|
roundingMode: "halfExpand"
|
||||||
|
}), 2, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||||
|
TemporalHelpers.assertDuration(dt2.until(dt1, {
|
||||||
|
smallestUnit: "years",
|
||||||
|
roundingMode: "halfExpand"
|
||||||
|
}), -1, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||||
|
|
28
test/built-ins/Temporal/ZonedDateTime/prototype/until/subseconds.js
vendored
Normal file
28
test/built-ins/Temporal/ZonedDateTime/prototype/until/subseconds.js
vendored
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.until
|
||||||
|
description: Can return subseconds.
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const feb20 = Temporal.ZonedDateTime.from("2020-02-01T00:00+01:00[+01:00]");
|
||||||
|
const feb21 = Temporal.ZonedDateTime.from("2021-02-01T00:00+01:00[+01:00]");
|
||||||
|
|
||||||
|
const later = feb20.add({
|
||||||
|
days: 1,
|
||||||
|
milliseconds: 250,
|
||||||
|
microseconds: 250,
|
||||||
|
nanoseconds: 250
|
||||||
|
});
|
||||||
|
|
||||||
|
const msDiff = feb20.until(later, { largestUnit: "milliseconds" });
|
||||||
|
TemporalHelpers.assertDuration(msDiff, 0, 0, 0, 0, 0, 0, 0, 86400250, 250, 250);
|
||||||
|
|
||||||
|
const µsDiff = feb20.until(later, { largestUnit: "microseconds" });
|
||||||
|
TemporalHelpers.assertDuration(µsDiff, 0, 0, 0, 0, 0, 0, 0, 0, 86400250250, 250);
|
||||||
|
|
||||||
|
const nsDiff = feb20.until(later, { largestUnit: "nanoseconds" });
|
||||||
|
TemporalHelpers.assertDuration(nsDiff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 86400250250250);
|
22
test/built-ins/Temporal/ZonedDateTime/prototype/until/until-since.js
vendored
Normal file
22
test/built-ins/Temporal/ZonedDateTime/prototype/until/until-since.js
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.until
|
||||||
|
description: zdt.until(later) === later.since(zdt) with default options.
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const zdt = Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789+01:00[+01:00]");
|
||||||
|
|
||||||
|
const later = Temporal.ZonedDateTime.from({
|
||||||
|
year: 2016,
|
||||||
|
month: 3,
|
||||||
|
day: 3,
|
||||||
|
hour: 18,
|
||||||
|
timeZone: "+01:00"
|
||||||
|
});
|
||||||
|
|
||||||
|
TemporalHelpers.assertDurationsEqual(zdt.until(later),
|
||||||
|
later.since(zdt));
|
81
test/built-ins/Temporal/ZonedDateTime/prototype/until/valid-rounding-increments.js
vendored
Normal file
81
test/built-ins/Temporal/ZonedDateTime/prototype/until/valid-rounding-increments.js
vendored
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.until
|
||||||
|
description: Valid increments are based on divisibility.
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const earlier = new Temporal.ZonedDateTime(0n, "+01:00");
|
||||||
|
const later = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "+01:00");
|
||||||
|
|
||||||
|
// valid hour increments divide into 24
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
6,
|
||||||
|
8,
|
||||||
|
12
|
||||||
|
].forEach(roundingIncrement => {
|
||||||
|
var options = {
|
||||||
|
smallestUnit: "hours",
|
||||||
|
roundingIncrement
|
||||||
|
};
|
||||||
|
assert(earlier.until(later, options) instanceof Temporal.Duration);
|
||||||
|
});
|
||||||
|
[
|
||||||
|
"minutes",
|
||||||
|
"seconds"
|
||||||
|
].forEach(smallestUnit => {
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
5,
|
||||||
|
6,
|
||||||
|
10,
|
||||||
|
12,
|
||||||
|
15,
|
||||||
|
20,
|
||||||
|
30
|
||||||
|
].forEach(roundingIncrement => {
|
||||||
|
var options = {
|
||||||
|
smallestUnit,
|
||||||
|
roundingIncrement
|
||||||
|
};
|
||||||
|
assert(earlier.until(later, options) instanceof Temporal.Duration);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
[
|
||||||
|
"milliseconds",
|
||||||
|
"microseconds",
|
||||||
|
"nanoseconds"
|
||||||
|
].forEach(smallestUnit => {
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
5,
|
||||||
|
8,
|
||||||
|
10,
|
||||||
|
20,
|
||||||
|
25,
|
||||||
|
40,
|
||||||
|
50,
|
||||||
|
100,
|
||||||
|
125,
|
||||||
|
200,
|
||||||
|
250,
|
||||||
|
500
|
||||||
|
].forEach(roundingIncrement => {
|
||||||
|
var options = {
|
||||||
|
smallestUnit,
|
||||||
|
roundingIncrement
|
||||||
|
};
|
||||||
|
assert(earlier.until(later, options) instanceof Temporal.Duration);
|
||||||
|
});
|
||||||
|
});
|
21
test/built-ins/Temporal/ZonedDateTime/prototype/until/weeks-and-months-are-mutually-exclusive.js
vendored
Normal file
21
test/built-ins/Temporal/ZonedDateTime/prototype/until/weeks-and-months-are-mutually-exclusive.js
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.until
|
||||||
|
description: Weeks and months are mutually exclusive.
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const zdt = Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789+01:00[+01:00]");
|
||||||
|
|
||||||
|
const laterDateTime = zdt.add({
|
||||||
|
days: 42,
|
||||||
|
hours: 3
|
||||||
|
});
|
||||||
|
const weeksDifference = zdt.until(laterDateTime, { largestUnit: "weeks" });
|
||||||
|
assert.notSameValue(weeksDifference.weeks, 0);
|
||||||
|
assert.sameValue(weeksDifference.months, 0);
|
||||||
|
const monthsDifference = zdt.until(laterDateTime, { largestUnit: "months" });
|
||||||
|
assert.sameValue(monthsDifference.weeks, 0);
|
||||||
|
assert.notSameValue(monthsDifference.months, 0);
|
@ -1,279 +0,0 @@
|
|||||||
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal-zoneddatetime-objects
|
|
||||||
description: Temporal.ZonedDateTime.prototype.since()
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
var zdt = Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789+01:00[+01:00]");
|
|
||||||
|
|
||||||
// zdt.since(earlier) === earlier.until(zdt) with default options
|
|
||||||
var earlier = Temporal.ZonedDateTime.from({
|
|
||||||
year: 1966,
|
|
||||||
month: 3,
|
|
||||||
day: 3,
|
|
||||||
hour: 18,
|
|
||||||
timeZone: "+01:00"
|
|
||||||
});
|
|
||||||
assert.sameValue(`${ zdt.since(earlier) }`, `${ earlier.until(zdt) }`);
|
|
||||||
|
|
||||||
// casts argument
|
|
||||||
assert.sameValue(`${ zdt.since({
|
|
||||||
year: 2019,
|
|
||||||
month: 10,
|
|
||||||
day: 29,
|
|
||||||
hour: 10,
|
|
||||||
timeZone: "+01:00"
|
|
||||||
}) }`, "-PT376434H36M29.876543211S");
|
|
||||||
assert.sameValue(`${ zdt.since("2019-10-29T10:46:38.271986102+01:00[+01:00]") }`, "-PT376435H23M8.148529313S");
|
|
||||||
var feb20 = Temporal.ZonedDateTime.from("2020-02-01T00:00+01:00[+01:00]");
|
|
||||||
var feb21 = Temporal.ZonedDateTime.from("2021-02-01T00:00+01:00[+01:00]");
|
|
||||||
|
|
||||||
// defaults to returning hours
|
|
||||||
assert.sameValue(`${ feb21.since(feb20) }`, "PT8784H");
|
|
||||||
assert.sameValue(`${ feb21.since(feb20, { largestUnit: "auto" }) }`, "PT8784H");
|
|
||||||
assert.sameValue(`${ feb21.since(feb20, { largestUnit: "hours" }) }`, "PT8784H");
|
|
||||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("2021-02-01T00:00:00.000000001+01:00[+01:00]").since(feb20) }`, "PT8784H0.000000001S");
|
|
||||||
assert.sameValue(`${ feb21.since(Temporal.ZonedDateTime.from("2020-02-01T00:00:00.000000001+01:00[+01:00]")) }`, "PT8783H59M59.999999999S");
|
|
||||||
|
|
||||||
// can return lower or higher units
|
|
||||||
assert.sameValue(`${ feb21.since(feb20, { largestUnit: "years" }) }`, "P1Y");
|
|
||||||
assert.sameValue(`${ feb21.since(feb20, { largestUnit: "months" }) }`, "P12M");
|
|
||||||
assert.sameValue(`${ feb21.since(feb20, { largestUnit: "weeks" }) }`, "P52W2D");
|
|
||||||
assert.sameValue(`${ feb21.since(feb20, { largestUnit: "days" }) }`, "P366D");
|
|
||||||
assert.sameValue(`${ feb21.since(feb20, { largestUnit: "minutes" }) }`, "PT527040M");
|
|
||||||
assert.sameValue(`${ feb21.since(feb20, { largestUnit: "seconds" }) }`, "PT31622400S");
|
|
||||||
|
|
||||||
// can return subseconds
|
|
||||||
var later = feb20.add({
|
|
||||||
days: 1,
|
|
||||||
milliseconds: 250,
|
|
||||||
microseconds: 250,
|
|
||||||
nanoseconds: 250
|
|
||||||
});
|
|
||||||
var msDiff = later.since(feb20, { largestUnit: "milliseconds" });
|
|
||||||
assert.sameValue(msDiff.seconds, 0);
|
|
||||||
assert.sameValue(msDiff.milliseconds, 86400250);
|
|
||||||
assert.sameValue(msDiff.microseconds, 250);
|
|
||||||
assert.sameValue(msDiff.nanoseconds, 250);
|
|
||||||
var µsDiff = later.since(feb20, { largestUnit: "microseconds" });
|
|
||||||
assert.sameValue(µsDiff.milliseconds, 0);
|
|
||||||
assert.sameValue(µsDiff.microseconds, 86400250250);
|
|
||||||
assert.sameValue(µsDiff.nanoseconds, 250);
|
|
||||||
var nsDiff = later.since(feb20, { largestUnit: "nanoseconds" });
|
|
||||||
assert.sameValue(nsDiff.microseconds, 0);
|
|
||||||
assert.sameValue(nsDiff.nanoseconds, 86400250250250);
|
|
||||||
|
|
||||||
// does not include higher units than necessary
|
|
||||||
var lastFeb20 = Temporal.ZonedDateTime.from("2020-02-29T00:00+01:00[+01:00]");
|
|
||||||
var lastFeb21 = Temporal.ZonedDateTime.from("2021-02-28T00:00+01:00[+01:00]");
|
|
||||||
assert.sameValue(`${ lastFeb21.since(lastFeb20) }`, "PT8760H");
|
|
||||||
assert.sameValue(`${ lastFeb21.since(lastFeb20, { largestUnit: "months" }) }`, "P11M28D");
|
|
||||||
assert.sameValue(`${ lastFeb21.since(lastFeb20, { largestUnit: "years" }) }`, "P11M28D");
|
|
||||||
|
|
||||||
// weeks and months are mutually exclusive
|
|
||||||
var laterDateTime = zdt.add({
|
|
||||||
days: 42,
|
|
||||||
hours: 3
|
|
||||||
});
|
|
||||||
var weeksDifference = laterDateTime.since(zdt, { largestUnit: "weeks" });
|
|
||||||
assert.notSameValue(weeksDifference.weeks, 0);
|
|
||||||
assert.sameValue(weeksDifference.months, 0);
|
|
||||||
var monthsDifference = laterDateTime.since(zdt, { largestUnit: "months" });
|
|
||||||
assert.sameValue(monthsDifference.weeks, 0);
|
|
||||||
assert.notSameValue(monthsDifference.months, 0);
|
|
||||||
|
|
||||||
var earlier = Temporal.ZonedDateTime.from('2019-01-08T09:22:36.123456789+01:00[+01:00]');
|
|
||||||
var later = Temporal.ZonedDateTime.from('2021-09-07T13:39:40.987654321+01:00[+01:00]');
|
|
||||||
// assumes a different default for largestUnit if smallestUnit is larger than days
|
|
||||||
assert.sameValue(`${ later.since(earlier, {
|
|
||||||
smallestUnit: "years",
|
|
||||||
roundingMode: "halfExpand"
|
|
||||||
}) }`, "P3Y");
|
|
||||||
assert.sameValue(`${ later.since(earlier, {
|
|
||||||
smallestUnit: "months",
|
|
||||||
roundingMode: "halfExpand"
|
|
||||||
}) }`, "P32M");
|
|
||||||
assert.sameValue(`${ later.since(earlier, {
|
|
||||||
smallestUnit: "weeks",
|
|
||||||
roundingMode: "halfExpand"
|
|
||||||
}) }`, "P139W");
|
|
||||||
|
|
||||||
// rounds to an increment of hours
|
|
||||||
assert.sameValue(`${ later.since(earlier, {
|
|
||||||
smallestUnit: "hours",
|
|
||||||
roundingIncrement: 3,
|
|
||||||
roundingMode: "halfExpand"
|
|
||||||
}) }`, "PT23355H");
|
|
||||||
|
|
||||||
// rounds to an increment of minutes
|
|
||||||
assert.sameValue(`${ later.since(earlier, {
|
|
||||||
smallestUnit: "minutes",
|
|
||||||
roundingIncrement: 30,
|
|
||||||
roundingMode: "halfExpand"
|
|
||||||
}) }`, "PT23356H30M");
|
|
||||||
|
|
||||||
// rounds to an increment of seconds
|
|
||||||
assert.sameValue(`${ later.since(earlier, {
|
|
||||||
smallestUnit: "seconds",
|
|
||||||
roundingIncrement: 15,
|
|
||||||
roundingMode: "halfExpand"
|
|
||||||
}) }`, "PT23356H17M");
|
|
||||||
|
|
||||||
// rounds to an increment of milliseconds
|
|
||||||
assert.sameValue(`${ later.since(earlier, {
|
|
||||||
smallestUnit: "milliseconds",
|
|
||||||
roundingIncrement: 10,
|
|
||||||
roundingMode: "halfExpand"
|
|
||||||
}) }`, "PT23356H17M4.86S");
|
|
||||||
|
|
||||||
// rounds to an increment of microseconds
|
|
||||||
assert.sameValue(`${ later.since(earlier, {
|
|
||||||
smallestUnit: "microseconds",
|
|
||||||
roundingIncrement: 10,
|
|
||||||
roundingMode: "halfExpand"
|
|
||||||
}) }`, "PT23356H17M4.8642S");
|
|
||||||
|
|
||||||
// rounds to an increment of nanoseconds
|
|
||||||
assert.sameValue(`${ later.since(earlier, {
|
|
||||||
smallestUnit: "nanoseconds",
|
|
||||||
roundingIncrement: 10,
|
|
||||||
roundingMode: "halfExpand"
|
|
||||||
}) }`, "PT23356H17M4.86419753S");
|
|
||||||
|
|
||||||
// valid hour increments divide into 24
|
|
||||||
[
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
3,
|
|
||||||
4,
|
|
||||||
6,
|
|
||||||
8,
|
|
||||||
12
|
|
||||||
].forEach(roundingIncrement => {
|
|
||||||
var options = {
|
|
||||||
smallestUnit: "hours",
|
|
||||||
roundingIncrement
|
|
||||||
};
|
|
||||||
assert(later.since(earlier, options) instanceof Temporal.Duration);
|
|
||||||
});
|
|
||||||
[
|
|
||||||
"minutes",
|
|
||||||
"seconds"
|
|
||||||
].forEach(smallestUnit => {
|
|
||||||
[
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
3,
|
|
||||||
4,
|
|
||||||
5,
|
|
||||||
6,
|
|
||||||
10,
|
|
||||||
12,
|
|
||||||
15,
|
|
||||||
20,
|
|
||||||
30
|
|
||||||
].forEach(roundingIncrement => {
|
|
||||||
var options = {
|
|
||||||
smallestUnit,
|
|
||||||
roundingIncrement
|
|
||||||
};
|
|
||||||
assert(later.since(earlier, options) instanceof Temporal.Duration);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
[
|
|
||||||
"milliseconds",
|
|
||||||
"microseconds",
|
|
||||||
"nanoseconds"
|
|
||||||
].forEach(smallestUnit => {
|
|
||||||
[
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
4,
|
|
||||||
5,
|
|
||||||
8,
|
|
||||||
10,
|
|
||||||
20,
|
|
||||||
25,
|
|
||||||
40,
|
|
||||||
50,
|
|
||||||
100,
|
|
||||||
125,
|
|
||||||
200,
|
|
||||||
250,
|
|
||||||
500
|
|
||||||
].forEach(roundingIncrement => {
|
|
||||||
var options = {
|
|
||||||
smallestUnit,
|
|
||||||
roundingIncrement
|
|
||||||
};
|
|
||||||
assert(later.since(earlier, options) instanceof Temporal.Duration);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// throws on increments that do not divide evenly into the next highest
|
|
||||||
assert.throws(RangeError, () => later.since(earlier, {
|
|
||||||
smallestUnit: "hours",
|
|
||||||
roundingIncrement: 11
|
|
||||||
}));
|
|
||||||
assert.throws(RangeError, () => later.since(earlier, {
|
|
||||||
smallestUnit: "minutes",
|
|
||||||
roundingIncrement: 29
|
|
||||||
}));
|
|
||||||
assert.throws(RangeError, () => later.since(earlier, {
|
|
||||||
smallestUnit: "seconds",
|
|
||||||
roundingIncrement: 29
|
|
||||||
}));
|
|
||||||
assert.throws(RangeError, () => later.since(earlier, {
|
|
||||||
smallestUnit: "milliseconds",
|
|
||||||
roundingIncrement: 29
|
|
||||||
}));
|
|
||||||
assert.throws(RangeError, () => later.since(earlier, {
|
|
||||||
smallestUnit: "microseconds",
|
|
||||||
roundingIncrement: 29
|
|
||||||
}));
|
|
||||||
assert.throws(RangeError, () => later.since(earlier, {
|
|
||||||
smallestUnit: "nanoseconds",
|
|
||||||
roundingIncrement: 29
|
|
||||||
}));
|
|
||||||
|
|
||||||
// throws on increments that are equal to the next highest
|
|
||||||
assert.throws(RangeError, () => later.since(earlier, {
|
|
||||||
smallestUnit: "hours",
|
|
||||||
roundingIncrement: 24
|
|
||||||
}));
|
|
||||||
assert.throws(RangeError, () => later.since(earlier, {
|
|
||||||
smallestUnit: "minutes",
|
|
||||||
roundingIncrement: 60
|
|
||||||
}));
|
|
||||||
assert.throws(RangeError, () => later.since(earlier, {
|
|
||||||
smallestUnit: "seconds",
|
|
||||||
roundingIncrement: 60
|
|
||||||
}));
|
|
||||||
assert.throws(RangeError, () => later.since(earlier, {
|
|
||||||
smallestUnit: "milliseconds",
|
|
||||||
roundingIncrement: 1000
|
|
||||||
}));
|
|
||||||
assert.throws(RangeError, () => later.since(earlier, {
|
|
||||||
smallestUnit: "microseconds",
|
|
||||||
roundingIncrement: 1000
|
|
||||||
}));
|
|
||||||
assert.throws(RangeError, () => later.since(earlier, {
|
|
||||||
smallestUnit: "nanoseconds",
|
|
||||||
roundingIncrement: 1000
|
|
||||||
}));
|
|
||||||
|
|
||||||
// rounds relative to the receiver
|
|
||||||
var dt1 = Temporal.ZonedDateTime.from("2019-01-01T00:00+00:00[UTC]");
|
|
||||||
var dt2 = Temporal.ZonedDateTime.from("2020-07-02T00:00+00:00[UTC]");
|
|
||||||
assert.sameValue(`${ dt2.since(dt1, {
|
|
||||||
smallestUnit: "years",
|
|
||||||
roundingMode: "halfExpand"
|
|
||||||
}) }`, "P1Y");
|
|
||||||
assert.sameValue(`${ dt1.since(dt2, {
|
|
||||||
smallestUnit: "years",
|
|
||||||
roundingMode: "halfExpand"
|
|
||||||
}) }`, "-P2Y");
|
|
||||||
|
|
@ -1,283 +0,0 @@
|
|||||||
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal-zoneddatetime-objects
|
|
||||||
description: Temporal.ZonedDateTime.prototype.until()
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
var zdt = Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789+01:00[+01:00]");
|
|
||||||
|
|
||||||
// zdt.until(later) === later.since(zdt) with default options
|
|
||||||
var later = Temporal.ZonedDateTime.from({
|
|
||||||
year: 2016,
|
|
||||||
month: 3,
|
|
||||||
day: 3,
|
|
||||||
hour: 18,
|
|
||||||
timeZone: "+01:00"
|
|
||||||
});
|
|
||||||
assert.sameValue(`${ zdt.until(later) }`, `${ later.since(zdt) }`);
|
|
||||||
|
|
||||||
// casts argument
|
|
||||||
assert.sameValue(`${ zdt.until({
|
|
||||||
year: 2019,
|
|
||||||
month: 10,
|
|
||||||
day: 29,
|
|
||||||
hour: 10,
|
|
||||||
timeZone: "+01:00"
|
|
||||||
}) }`, "PT376434H36M29.876543211S");
|
|
||||||
assert.sameValue(`${ zdt.until("2019-10-29T10:46:38.271986102+01:00[+01:00]") }`, "PT376435H23M8.148529313S");
|
|
||||||
var feb20 = Temporal.ZonedDateTime.from("2020-02-01T00:00+01:00[+01:00]");
|
|
||||||
var feb21 = Temporal.ZonedDateTime.from("2021-02-01T00:00+01:00[+01:00]");
|
|
||||||
|
|
||||||
// defaults to returning hours
|
|
||||||
assert.sameValue(`${ feb20.until(feb21) }`, "PT8784H");
|
|
||||||
assert.sameValue(`${ feb20.until(feb21, { largestUnit: "auto" }) }`, "PT8784H");
|
|
||||||
assert.sameValue(`${ feb20.until(feb21, { largestUnit: "hours" }) }`, "PT8784H");
|
|
||||||
assert.sameValue(`${ feb20.until(Temporal.ZonedDateTime.from("2021-02-01T00:00:00.000000001+01:00[+01:00]")) }`, "PT8784H0.000000001S");
|
|
||||||
assert.sameValue(`${ Temporal.ZonedDateTime.from("2020-02-01T00:00:00.000000001+01:00[+01:00]").until(feb21) }`, "PT8783H59M59.999999999S");
|
|
||||||
|
|
||||||
// can return lower or higher units
|
|
||||||
assert.sameValue(`${ feb20.until(feb21, { largestUnit: "years" }) }`, "P1Y");
|
|
||||||
assert.sameValue(`${ feb20.until(feb21, { largestUnit: "months" }) }`, "P12M");
|
|
||||||
assert.sameValue(`${ feb20.until(feb21, { largestUnit: "weeks" }) }`, "P52W2D");
|
|
||||||
assert.sameValue(`${ feb20.until(feb21, { largestUnit: "days" }) }`, "P366D");
|
|
||||||
assert.sameValue(`${ feb20.until(feb21, { largestUnit: "minutes" }) }`, "PT527040M");
|
|
||||||
assert.sameValue(`${ feb20.until(feb21, { largestUnit: "seconds" }) }`, "PT31622400S");
|
|
||||||
|
|
||||||
// can return subseconds
|
|
||||||
var later = feb20.add({
|
|
||||||
days: 1,
|
|
||||||
milliseconds: 250,
|
|
||||||
microseconds: 250,
|
|
||||||
nanoseconds: 250
|
|
||||||
});
|
|
||||||
var msDiff = feb20.until(later, { largestUnit: "milliseconds" });
|
|
||||||
assert.sameValue(msDiff.seconds, 0);
|
|
||||||
assert.sameValue(msDiff.milliseconds, 86400250);
|
|
||||||
assert.sameValue(msDiff.microseconds, 250);
|
|
||||||
assert.sameValue(msDiff.nanoseconds, 250);
|
|
||||||
var µsDiff = feb20.until(later, { largestUnit: "microseconds" });
|
|
||||||
assert.sameValue(µsDiff.milliseconds, 0);
|
|
||||||
assert.sameValue(µsDiff.microseconds, 86400250250);
|
|
||||||
assert.sameValue(µsDiff.nanoseconds, 250);
|
|
||||||
var nsDiff = feb20.until(later, { largestUnit: "nanoseconds" });
|
|
||||||
assert.sameValue(nsDiff.microseconds, 0);
|
|
||||||
assert.sameValue(nsDiff.nanoseconds, 86400250250250);
|
|
||||||
|
|
||||||
// does not include higher units than necessary
|
|
||||||
var lastFeb20 = Temporal.ZonedDateTime.from("2020-02-29T00:00+01:00[+01:00]");
|
|
||||||
var lastJan21 = Temporal.ZonedDateTime.from("2021-01-31T00:00+01:00[+01:00]");
|
|
||||||
assert.sameValue(`${ lastFeb20.until(lastJan21) }`, "PT8088H");
|
|
||||||
assert.sameValue(`${ lastFeb20.until(lastJan21, { largestUnit: "months" }) }`, "P11M2D");
|
|
||||||
assert.sameValue(`${ lastFeb20.until(lastJan21, { largestUnit: "years" }) }`, "P11M2D");
|
|
||||||
|
|
||||||
// weeks and months are mutually exclusive
|
|
||||||
var laterDateTime = zdt.add({
|
|
||||||
days: 42,
|
|
||||||
hours: 3
|
|
||||||
});
|
|
||||||
var weeksDifference = zdt.until(laterDateTime, { largestUnit: "weeks" });
|
|
||||||
assert.notSameValue(weeksDifference.weeks, 0);
|
|
||||||
assert.sameValue(weeksDifference.months, 0);
|
|
||||||
var monthsDifference = zdt.until(laterDateTime, { largestUnit: "months" });
|
|
||||||
assert.sameValue(monthsDifference.weeks, 0);
|
|
||||||
assert.notSameValue(monthsDifference.months, 0);
|
|
||||||
|
|
||||||
var earlier = Temporal.ZonedDateTime.from('2019-01-08T09:22:36.123456789+01:00[+01:00]');
|
|
||||||
var later = Temporal.ZonedDateTime.from('2021-09-07T13:39:40.987654321+01:00[+01:00]');
|
|
||||||
// assumes a different default for largestUnit if smallestUnit is larger than hours
|
|
||||||
assert.sameValue(`${ earlier.until(later, {
|
|
||||||
smallestUnit: "years",
|
|
||||||
roundingMode: "halfExpand"
|
|
||||||
}) }`, "P3Y");
|
|
||||||
assert.sameValue(`${ earlier.until(later, {
|
|
||||||
smallestUnit: "months",
|
|
||||||
roundingMode: "halfExpand"
|
|
||||||
}) }`, "P32M");
|
|
||||||
assert.sameValue(`${ earlier.until(later, {
|
|
||||||
smallestUnit: "weeks",
|
|
||||||
roundingMode: "halfExpand"
|
|
||||||
}) }`, "P139W");
|
|
||||||
assert.sameValue(`${ earlier.until(later, {
|
|
||||||
smallestUnit: "days",
|
|
||||||
roundingMode: "halfExpand"
|
|
||||||
}) }`, "P973D");
|
|
||||||
|
|
||||||
// rounds to an increment of hours
|
|
||||||
assert.sameValue(`${ earlier.until(later, {
|
|
||||||
smallestUnit: "hours",
|
|
||||||
roundingIncrement: 3,
|
|
||||||
roundingMode: "halfExpand"
|
|
||||||
}) }`, "PT23355H");
|
|
||||||
|
|
||||||
// rounds to an increment of minutes
|
|
||||||
assert.sameValue(`${ earlier.until(later, {
|
|
||||||
smallestUnit: "minutes",
|
|
||||||
roundingIncrement: 30,
|
|
||||||
roundingMode: "halfExpand"
|
|
||||||
}) }`, "PT23356H30M");
|
|
||||||
|
|
||||||
// rounds to an increment of seconds
|
|
||||||
assert.sameValue(`${ earlier.until(later, {
|
|
||||||
smallestUnit: "seconds",
|
|
||||||
roundingIncrement: 15,
|
|
||||||
roundingMode: "halfExpand"
|
|
||||||
}) }`, "PT23356H17M");
|
|
||||||
|
|
||||||
// rounds to an increment of milliseconds
|
|
||||||
assert.sameValue(`${ earlier.until(later, {
|
|
||||||
smallestUnit: "milliseconds",
|
|
||||||
roundingIncrement: 10,
|
|
||||||
roundingMode: "halfExpand"
|
|
||||||
}) }`, "PT23356H17M4.86S");
|
|
||||||
|
|
||||||
// rounds to an increment of microseconds
|
|
||||||
assert.sameValue(`${ earlier.until(later, {
|
|
||||||
smallestUnit: "microseconds",
|
|
||||||
roundingIncrement: 10,
|
|
||||||
roundingMode: "halfExpand"
|
|
||||||
}) }`, "PT23356H17M4.8642S");
|
|
||||||
|
|
||||||
// rounds to an increment of nanoseconds
|
|
||||||
assert.sameValue(`${ earlier.until(later, {
|
|
||||||
smallestUnit: "nanoseconds",
|
|
||||||
roundingIncrement: 10,
|
|
||||||
roundingMode: "halfExpand"
|
|
||||||
}) }`, "PT23356H17M4.86419753S");
|
|
||||||
|
|
||||||
// valid hour increments divide into 24
|
|
||||||
[
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
3,
|
|
||||||
4,
|
|
||||||
6,
|
|
||||||
8,
|
|
||||||
12
|
|
||||||
].forEach(roundingIncrement => {
|
|
||||||
var options = {
|
|
||||||
smallestUnit: "hours",
|
|
||||||
roundingIncrement
|
|
||||||
};
|
|
||||||
assert(earlier.until(later, options) instanceof Temporal.Duration);
|
|
||||||
});
|
|
||||||
[
|
|
||||||
"minutes",
|
|
||||||
"seconds"
|
|
||||||
].forEach(smallestUnit => {
|
|
||||||
[
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
3,
|
|
||||||
4,
|
|
||||||
5,
|
|
||||||
6,
|
|
||||||
10,
|
|
||||||
12,
|
|
||||||
15,
|
|
||||||
20,
|
|
||||||
30
|
|
||||||
].forEach(roundingIncrement => {
|
|
||||||
var options = {
|
|
||||||
smallestUnit,
|
|
||||||
roundingIncrement
|
|
||||||
};
|
|
||||||
assert(earlier.until(later, options) instanceof Temporal.Duration);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
[
|
|
||||||
"milliseconds",
|
|
||||||
"microseconds",
|
|
||||||
"nanoseconds"
|
|
||||||
].forEach(smallestUnit => {
|
|
||||||
[
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
4,
|
|
||||||
5,
|
|
||||||
8,
|
|
||||||
10,
|
|
||||||
20,
|
|
||||||
25,
|
|
||||||
40,
|
|
||||||
50,
|
|
||||||
100,
|
|
||||||
125,
|
|
||||||
200,
|
|
||||||
250,
|
|
||||||
500
|
|
||||||
].forEach(roundingIncrement => {
|
|
||||||
var options = {
|
|
||||||
smallestUnit,
|
|
||||||
roundingIncrement
|
|
||||||
};
|
|
||||||
assert(earlier.until(later, options) instanceof Temporal.Duration);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// throws on increments that do not divide evenly into the next highest
|
|
||||||
assert.throws(RangeError, () => earlier.until(later, {
|
|
||||||
smallestUnit: "hours",
|
|
||||||
roundingIncrement: 11
|
|
||||||
}));
|
|
||||||
assert.throws(RangeError, () => earlier.until(later, {
|
|
||||||
smallestUnit: "minutes",
|
|
||||||
roundingIncrement: 29
|
|
||||||
}));
|
|
||||||
assert.throws(RangeError, () => earlier.until(later, {
|
|
||||||
smallestUnit: "seconds",
|
|
||||||
roundingIncrement: 29
|
|
||||||
}));
|
|
||||||
assert.throws(RangeError, () => earlier.until(later, {
|
|
||||||
smallestUnit: "milliseconds",
|
|
||||||
roundingIncrement: 29
|
|
||||||
}));
|
|
||||||
assert.throws(RangeError, () => earlier.until(later, {
|
|
||||||
smallestUnit: "microseconds",
|
|
||||||
roundingIncrement: 29
|
|
||||||
}));
|
|
||||||
assert.throws(RangeError, () => earlier.until(later, {
|
|
||||||
smallestUnit: "nanoseconds",
|
|
||||||
roundingIncrement: 29
|
|
||||||
}));
|
|
||||||
|
|
||||||
// throws on increments that are equal to the next highest
|
|
||||||
assert.throws(RangeError, () => earlier.until(later, {
|
|
||||||
smallestUnit: "hours",
|
|
||||||
roundingIncrement: 24
|
|
||||||
}));
|
|
||||||
assert.throws(RangeError, () => earlier.until(later, {
|
|
||||||
smallestUnit: "minutes",
|
|
||||||
roundingIncrement: 60
|
|
||||||
}));
|
|
||||||
assert.throws(RangeError, () => earlier.until(later, {
|
|
||||||
smallestUnit: "seconds",
|
|
||||||
roundingIncrement: 60
|
|
||||||
}));
|
|
||||||
assert.throws(RangeError, () => earlier.until(later, {
|
|
||||||
smallestUnit: "milliseconds",
|
|
||||||
roundingIncrement: 1000
|
|
||||||
}));
|
|
||||||
assert.throws(RangeError, () => earlier.until(later, {
|
|
||||||
smallestUnit: "microseconds",
|
|
||||||
roundingIncrement: 1000
|
|
||||||
}));
|
|
||||||
assert.throws(RangeError, () => earlier.until(later, {
|
|
||||||
smallestUnit: "nanoseconds",
|
|
||||||
roundingIncrement: 1000
|
|
||||||
}));
|
|
||||||
|
|
||||||
// rounds relative to the receiver
|
|
||||||
var dt1 = Temporal.ZonedDateTime.from("2019-01-01T00:00+00:00[UTC]");
|
|
||||||
var dt2 = Temporal.ZonedDateTime.from("2020-07-02T00:00+00:00[UTC]");
|
|
||||||
assert.sameValue(`${ dt1.until(dt2, {
|
|
||||||
smallestUnit: "years",
|
|
||||||
roundingMode: "halfExpand"
|
|
||||||
}) }`, "P2Y");
|
|
||||||
assert.sameValue(`${ dt2.until(dt1, {
|
|
||||||
smallestUnit: "years",
|
|
||||||
roundingMode: "halfExpand"
|
|
||||||
}) }`, "-P1Y");
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user