mirror of https://github.com/tc39/test262.git
Temporal: Adjust tests for Duration rounding fix
A MoveRelativeZonedDateTime step was missing, causing incorrect results. See https://github.com/tc39/proposal-temporal/issues/2742
This commit is contained in:
parent
9b4c6577f6
commit
6c6c72b063
|
@ -24,7 +24,7 @@ const relativeTo = new Temporal.ZonedDateTime(0n, timeZone, calendar);
|
||||||
|
|
||||||
const instance1 = new Temporal.Duration(1, 1, 1, 1, 1);
|
const instance1 = new Temporal.Duration(1, 1, 1, 1, 1);
|
||||||
instance1.round({ smallestUnit: "weeks", relativeTo });
|
instance1.round({ smallestUnit: "weeks", relativeTo });
|
||||||
assert.sameValue(calendar.dateAddCallCount, 3, "rounding with calendar smallestUnit");
|
assert.sameValue(calendar.dateAddCallCount, 4, "rounding with calendar smallestUnit");
|
||||||
|
|
||||||
// Rounding with a non-default largestUnit to cover the path in
|
// Rounding with a non-default largestUnit to cover the path in
|
||||||
// UnbalanceDurationRelative where larger units are converted into smaller
|
// UnbalanceDurationRelative where larger units are converted into smaller
|
||||||
|
@ -41,7 +41,7 @@ calendar.dateAddCallCount = 0;
|
||||||
|
|
||||||
const instance2 = new Temporal.Duration(0, 1, 1, 1);
|
const instance2 = new Temporal.Duration(0, 1, 1, 1);
|
||||||
instance2.round({ largestUnit: "weeks", smallestUnit: "weeks", relativeTo });
|
instance2.round({ largestUnit: "weeks", smallestUnit: "weeks", relativeTo });
|
||||||
assert.sameValue(calendar.dateAddCallCount, 5, "rounding with non-default largestUnit and calendar smallestUnit");
|
assert.sameValue(calendar.dateAddCallCount, 6, "rounding with non-default largestUnit and calendar smallestUnit");
|
||||||
|
|
||||||
// Rounding with smallestUnit days only.
|
// Rounding with smallestUnit days only.
|
||||||
// The calls come from these paths:
|
// The calls come from these paths:
|
||||||
|
@ -54,4 +54,4 @@ calendar.dateAddCallCount = 0;
|
||||||
|
|
||||||
const instance3 = new Temporal.Duration(1, 1, 1, 1, 1);
|
const instance3 = new Temporal.Duration(1, 1, 1, 1, 1);
|
||||||
instance3.round({ smallestUnit: "days", relativeTo });
|
instance3.round({ smallestUnit: "days", relativeTo });
|
||||||
assert.sameValue(calendar.dateAddCallCount, 2, "rounding with days smallestUnit");
|
assert.sameValue(calendar.dateAddCallCount, 3, "rounding with days smallestUnit");
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
// Copyright (C) 2024 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: >
|
||||||
|
Balancing the resulting duration takes the time zone's UTC offset shifts
|
||||||
|
into account
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
||||||
|
|
||||||
|
// Based on a test case by Adam Shaw
|
||||||
|
{
|
||||||
|
const duration = new Temporal.Duration(1, 0, 0, 0, 24);
|
||||||
|
const relativeTo = new Temporal.ZonedDateTime(
|
||||||
|
941184000_000_000_000n /* = 1999-10-29T08Z */,
|
||||||
|
timeZone); /* = 1999-10-29T00-08 in local time */
|
||||||
|
|
||||||
|
const result = duration.round({ largestUnit: "years", relativeTo });
|
||||||
|
TemporalHelpers.assertDuration(result, 1, 0, 0, 0, 24, 0, 0, 0, 0, 0,
|
||||||
|
"24 hours does not balance to 1 day in 25-hour day");
|
||||||
|
}
|
|
@ -394,6 +394,9 @@ const expectedOpsForYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([
|
||||||
"call options.relativeTo.calendar.dateUntil", // 12.n
|
"call options.relativeTo.calendar.dateUntil", // 12.n
|
||||||
"call options.relativeTo.calendar.dateAdd", // 12.r MoveRelativeDate
|
"call options.relativeTo.calendar.dateAdd", // 12.r MoveRelativeDate
|
||||||
"call options.relativeTo.calendar.dateAdd", // 12.x MoveRelativeDate
|
"call options.relativeTo.calendar.dateAdd", // 12.x MoveRelativeDate
|
||||||
|
// MoveRelativeZonedDateTime → AddZonedDateTime
|
||||||
|
"call options.relativeTo.calendar.dateAdd",
|
||||||
|
"call options.relativeTo.timeZone.getPossibleInstantsFor",
|
||||||
// BalanceDateDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call options.relativeTo.calendar.dateAdd", // 9.c
|
"call options.relativeTo.calendar.dateAdd", // 9.c
|
||||||
"call options.relativeTo.calendar.dateUntil", // 9.d
|
"call options.relativeTo.calendar.dateUntil", // 9.d
|
||||||
|
@ -420,6 +423,9 @@ const expectedOpsForUnbalanceRoundBalance = expectedOpsForZonedRelativeTo.concat
|
||||||
"call options.relativeTo.timeZone.getPossibleInstantsFor", // 13. GetInstantFor
|
"call options.relativeTo.timeZone.getPossibleInstantsFor", // 13. GetInstantFor
|
||||||
// RoundDuration
|
// RoundDuration
|
||||||
"call options.relativeTo.calendar.dateAdd", // 14.p MoveRelativeDate
|
"call options.relativeTo.calendar.dateAdd", // 14.p MoveRelativeDate
|
||||||
|
// MoveRelativeZonedDateTime → AddZonedDateTime
|
||||||
|
"call options.relativeTo.calendar.dateAdd",
|
||||||
|
"call options.relativeTo.timeZone.getPossibleInstantsFor",
|
||||||
// BalanceDateDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call options.relativeTo.calendar.dateAdd", // 10.d
|
"call options.relativeTo.calendar.dateAdd", // 10.d
|
||||||
"call options.relativeTo.calendar.dateUntil", // 10.e
|
"call options.relativeTo.calendar.dateUntil", // 10.e
|
||||||
|
@ -445,6 +451,9 @@ const expectedOpsForWeeksSpecialCase = expectedOpsForZonedRelativeTo.concat([
|
||||||
"call options.relativeTo.timeZone.getPossibleInstantsFor", // 13. GetInstantFor
|
"call options.relativeTo.timeZone.getPossibleInstantsFor", // 13. GetInstantFor
|
||||||
// RoundDuration
|
// RoundDuration
|
||||||
"call options.relativeTo.calendar.dateAdd", // 14.p MoveRelativeDate
|
"call options.relativeTo.calendar.dateAdd", // 14.p MoveRelativeDate
|
||||||
|
// MoveRelativeZonedDateTime → AddZonedDateTime
|
||||||
|
"call options.relativeTo.calendar.dateAdd",
|
||||||
|
"call options.relativeTo.timeZone.getPossibleInstantsFor",
|
||||||
]);
|
]);
|
||||||
new Temporal.Duration(0, 1, 1).round(createOptionsObserver({ largestUnit: "months", smallestUnit: "weeks", relativeTo: zonedRelativeTo }));
|
new Temporal.Duration(0, 1, 1).round(createOptionsObserver({ largestUnit: "months", smallestUnit: "weeks", relativeTo: zonedRelativeTo }));
|
||||||
assert.compareArray(
|
assert.compareArray(
|
||||||
|
|
|
@ -53,4 +53,4 @@ const relativeTo = { year: 2000, month: 5, day: 2, timeZone, calendar: nonBuilti
|
||||||
const instance = new Temporal.Duration(1, 0, 0, 0, 24);
|
const instance = new Temporal.Duration(1, 0, 0, 0, 24);
|
||||||
instance.round({ largestUnit: "years", relativeTo });
|
instance.round({ largestUnit: "years", relativeTo });
|
||||||
|
|
||||||
assert.sameValue(timeZone.calls, 6, "getPossibleInstantsFor should have been called 6 times");
|
assert.sameValue(timeZone.calls, 8, "getPossibleInstantsFor should have been called 8 times");
|
||||||
|
|
|
@ -36,6 +36,7 @@ const expected = [
|
||||||
"2000-01-01T00:00:00", // called once on the input relativeTo object
|
"2000-01-01T00:00:00", // called once on the input relativeTo object
|
||||||
"2001-02-09T00:00:00", // called once on relativeTo plus years, months, weeks, days from the receiver
|
"2001-02-09T00:00:00", // called once on relativeTo plus years, months, weeks, days from the receiver
|
||||||
"2001-02-10T00:00:00", // called once on the previous value plus the calendar days difference between that and the time part of the duration
|
"2001-02-10T00:00:00", // called once on the previous value plus the calendar days difference between that and the time part of the duration
|
||||||
|
"2001-02-01T00:00:00", // called once in the balancing step on intermediate relativeTo
|
||||||
];
|
];
|
||||||
|
|
||||||
TemporalHelpers.checkTimeZonePossibleInstantsIterable((timeZone) => {
|
TemporalHelpers.checkTimeZonePossibleInstantsIterable((timeZone) => {
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.duration.prototype.total
|
||||||
|
description: >
|
||||||
|
Balancing the resulting duration takes the time zone's UTC offset shifts
|
||||||
|
into account
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// Based on a test case by Adam Shaw
|
||||||
|
|
||||||
|
const duration = new Temporal.Duration(1, 0, 0, 0, 24);
|
||||||
|
const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
||||||
|
const relativeTo = new Temporal.ZonedDateTime(
|
||||||
|
941184000_000_000_000n /* = 1999-10-29T08Z */,
|
||||||
|
timeZone); /* = 1999-10-29T00-08 in local time */
|
||||||
|
|
||||||
|
const result = duration.total({ unit: "days", relativeTo });
|
||||||
|
assert.sameValue(result, 366.96, "24 hours does not balance to 1 day in 25-hour day");
|
26
test/built-ins/Temporal/ZonedDateTime/prototype/since/dst-balancing-result.js
vendored
Normal file
26
test/built-ins/Temporal/ZonedDateTime/prototype/since/dst-balancing-result.js
vendored
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
// Copyright (C) 2024 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: >
|
||||||
|
Balancing the resulting duration takes the time zone's UTC offset shifts
|
||||||
|
into account
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
||||||
|
|
||||||
|
// Based on a test case by Adam Shaw
|
||||||
|
{
|
||||||
|
const start = new Temporal.ZonedDateTime(
|
||||||
|
941184000_000_000_000n /* = 1999-10-29T08Z */,
|
||||||
|
timeZone); /* = 1999-10-29T00-08 in local time */
|
||||||
|
const end = new Temporal.ZonedDateTime(
|
||||||
|
972889200_000_000_000n /* = 2000-10-30T07Z */,
|
||||||
|
timeZone); /* = 2000-10-29T23-08 in local time */
|
||||||
|
|
||||||
|
const duration = start.since(end, { largestUnit: "years" });
|
||||||
|
TemporalHelpers.assertDuration(duration, -1, 0, 0, 0, -24, 0, 0, 0, 0, 0,
|
||||||
|
"24 hours does not balance to 1 day in 25-hour day");
|
||||||
|
}
|
26
test/built-ins/Temporal/ZonedDateTime/prototype/until/dst-balancing-result.js
vendored
Normal file
26
test/built-ins/Temporal/ZonedDateTime/prototype/until/dst-balancing-result.js
vendored
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
// Copyright (C) 2024 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: >
|
||||||
|
Balancing the resulting duration takes the time zone's UTC offset shifts
|
||||||
|
into account
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
||||||
|
|
||||||
|
// Based on a test case by Adam Shaw
|
||||||
|
{
|
||||||
|
const start = new Temporal.ZonedDateTime(
|
||||||
|
941184000_000_000_000n /* = 1999-10-29T08Z */,
|
||||||
|
timeZone); /* = 1999-10-29T00-08 in local time */
|
||||||
|
const end = new Temporal.ZonedDateTime(
|
||||||
|
972889200_000_000_000n /* = 2000-10-30T07Z */,
|
||||||
|
timeZone); /* = 2000-10-29T23-08 in local time */
|
||||||
|
|
||||||
|
const duration = start.until(end, { largestUnit: "years" });
|
||||||
|
TemporalHelpers.assertDuration(duration, 1, 0, 0, 0, 24, 0, 0, 0, 0, 0,
|
||||||
|
"24 hours does not balance to 1 day in 25-hour day");
|
||||||
|
}
|
|
@ -14,15 +14,15 @@ const instance = new Temporal.Duration(1, 0, 0, 0, 24);
|
||||||
|
|
||||||
let relativeTo = "2019-11-01T00:00[America/Vancouver]";
|
let relativeTo = "2019-11-01T00:00[America/Vancouver]";
|
||||||
const result4 = instance.round({ largestUnit: "years", relativeTo });
|
const result4 = instance.round({ largestUnit: "years", relativeTo });
|
||||||
TemporalHelpers.assertDuration(result4, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "date-time + IANA annotation is a zoned relativeTo");
|
TemporalHelpers.assertDuration(result4, 1, 0, 0, 0, 24, 0, 0, 0, 0, 0, "date-time + IANA annotation is a zoned relativeTo");
|
||||||
|
|
||||||
relativeTo = "2019-11-01T00:00Z[America/Vancouver]";
|
relativeTo = "2019-11-01T00:00Z[America/Vancouver]";
|
||||||
const result5 = instance.round({ largestUnit: "years", relativeTo });
|
const result5 = instance.round({ largestUnit: "years", relativeTo });
|
||||||
TemporalHelpers.assertDuration(result5, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "date-time + Z + IANA annotation is a zoned relativeTo");
|
TemporalHelpers.assertDuration(result5, 1, 0, 0, 0, 24, 0, 0, 0, 0, 0, "date-time + Z + IANA annotation is a zoned relativeTo");
|
||||||
|
|
||||||
relativeTo = "2019-11-01T00:00-07:00[America/Vancouver]";
|
relativeTo = "2019-11-01T00:00-07:00[America/Vancouver]";
|
||||||
const result6 = instance.round({ largestUnit: "years", relativeTo });
|
const result6 = instance.round({ largestUnit: "years", relativeTo });
|
||||||
TemporalHelpers.assertDuration(result6, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "date-time + offset + IANA annotation is a zoned relativeTo");
|
TemporalHelpers.assertDuration(result6, 1, 0, 0, 0, 24, 0, 0, 0, 0, 0, "date-time + offset + IANA annotation is a zoned relativeTo");
|
||||||
|
|
||||||
relativeTo = "2019-11-01T00:00+04:15[America/Vancouver]";
|
relativeTo = "2019-11-01T00:00+04:15[America/Vancouver]";
|
||||||
assert.throws(RangeError, () => instance.round({ largestUnit: "years", relativeTo }), "date-time + offset + IANA annotation throws if wall time and exact time mismatch");
|
assert.throws(RangeError, () => instance.round({ largestUnit: "years", relativeTo }), "date-time + offset + IANA annotation throws if wall time and exact time mismatch");
|
||||||
|
|
Loading…
Reference in New Issue