mirror of https://github.com/tc39/test262.git
adjust tests for round-zdt-day bugfix
This commit is contained in:
parent
b73f7d662d
commit
6c35fba9b2
|
@ -17,8 +17,6 @@ class TimeZone extends Temporal.TimeZone {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const units = ["hour", "minute", "second", "millisecond", "microsecond", "nanosecond"];
|
|
||||||
for (const smallestUnit of units) {
|
|
||||||
const zdt = new Temporal.ZonedDateTime(0n, new TimeZone("UTC"));
|
const zdt = new Temporal.ZonedDateTime(0n, new TimeZone("UTC"));
|
||||||
assert.throws(RangeError, () => zdt.round({ smallestUnit, roundingIncrement: 2 }), `zero day-length with smallestUnit ${smallestUnit}`);
|
|
||||||
}
|
assert.throws(RangeError, () => zdt.round({ smallestUnit: "day" }), `zero day-length with smallestUnit 'day'`);
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
// 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.round
|
|
||||||
description: >
|
|
||||||
UTC offset shift returned by adjacent invocations of getOffsetNanosecondsFor
|
|
||||||
in DisambiguatePossibleInstants cannot be greater than 24 hours.
|
|
||||||
features: [Temporal]
|
|
||||||
info: |
|
|
||||||
DisambiguatePossibleInstants:
|
|
||||||
18. If abs(_nanoseconds_) > nsPerDay, throw a *RangeError* exception.
|
|
||||||
---*/
|
|
||||||
|
|
||||||
class ShiftLonger24Hour extends Temporal.TimeZone {
|
|
||||||
id = 'TestTimeZone';
|
|
||||||
_shiftEpochNs = 12n * 3600n * 1_000_000_000n; // 1970-01-01T12:00Z
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
super('UTC');
|
|
||||||
}
|
|
||||||
|
|
||||||
getOffsetNanosecondsFor(instant) {
|
|
||||||
if (instant.epochNanoseconds < this._shiftEpochNs) return -12 * 3600e9;
|
|
||||||
return 12 * 3600e9 + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
getPossibleInstantsFor(plainDateTime) {
|
|
||||||
const [utcInstant] = super.getPossibleInstantsFor(plainDateTime);
|
|
||||||
const { year, month, day } = plainDateTime;
|
|
||||||
|
|
||||||
if (year < 1970) return [utcInstant.subtract({ hours: 12 })];
|
|
||||||
if (year === 1970 && month === 1 && day === 1) return [];
|
|
||||||
return [utcInstant.add({ hours: 12, nanoseconds: 1 })];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const timeZone = new ShiftLonger24Hour();
|
|
||||||
|
|
||||||
const instance = new Temporal.ZonedDateTime(0n, timeZone);
|
|
||||||
assert.throws(RangeError, () => instance.round({ smallestUnit: "hours" }), "RangeError should be thrown");
|
|
|
@ -50,6 +50,6 @@ const nonBuiltinISOCalendar = new Temporal.Calendar("iso8601");
|
||||||
const timeZone = new SkippedDateTime();
|
const timeZone = new SkippedDateTime();
|
||||||
|
|
||||||
const instance = new Temporal.ZonedDateTime(0n, timeZone, nonBuiltinISOCalendar);
|
const instance = new Temporal.ZonedDateTime(0n, timeZone, nonBuiltinISOCalendar);
|
||||||
instance.round({ smallestUnit: "hours" });
|
instance.round({ smallestUnit: "day" });
|
||||||
|
|
||||||
assert.sameValue(timeZone.calls, 6, "getPossibleInstantsFor should have been called 6 times");
|
assert.sameValue(timeZone.calls, 4, "getPossibleInstantsFor should have been called 4 times");
|
||||||
|
|
|
@ -23,10 +23,6 @@ const expected = [
|
||||||
"get this.timeZone.getPossibleInstantsFor",
|
"get this.timeZone.getPossibleInstantsFor",
|
||||||
// GetPlainDateTimeFor on receiver's instant
|
// GetPlainDateTimeFor on receiver's instant
|
||||||
"call this.timeZone.getOffsetNanosecondsFor",
|
"call this.timeZone.getOffsetNanosecondsFor",
|
||||||
// GetInstantFor on preceding midnight
|
|
||||||
"call this.timeZone.getPossibleInstantsFor",
|
|
||||||
// AddDaysToZonedDateTime
|
|
||||||
"call this.timeZone.getPossibleInstantsFor",
|
|
||||||
// InterpretISODateTimeOffset
|
// InterpretISODateTimeOffset
|
||||||
"call this.timeZone.getPossibleInstantsFor",
|
"call this.timeZone.getPossibleInstantsFor",
|
||||||
"call this.timeZone.getOffsetNanosecondsFor",
|
"call this.timeZone.getOffsetNanosecondsFor",
|
||||||
|
@ -83,36 +79,8 @@ beforeFallBackInstance.round(nextHourOptions);
|
||||||
assert.compareArray(actual, expected, "order of operations with rounding result at repeated wall-clock time");
|
assert.compareArray(actual, expected, "order of operations with rounding result at repeated wall-clock time");
|
||||||
actual.splice(0); // clear
|
actual.splice(0); // clear
|
||||||
|
|
||||||
const expectedSkippedDateTime = [
|
|
||||||
"get options.roundingIncrement",
|
|
||||||
"get options.roundingIncrement.valueOf",
|
|
||||||
"call options.roundingIncrement.valueOf",
|
|
||||||
"get options.roundingMode",
|
|
||||||
"get options.roundingMode.toString",
|
|
||||||
"call options.roundingMode.toString",
|
|
||||||
"get options.smallestUnit",
|
|
||||||
"get options.smallestUnit.toString",
|
|
||||||
"call options.smallestUnit.toString",
|
|
||||||
// lookup
|
|
||||||
"get this.timeZone.getOffsetNanosecondsFor",
|
|
||||||
"get this.timeZone.getPossibleInstantsFor",
|
|
||||||
// GetPlainDateTimeFor on receiver's instant
|
|
||||||
"call this.timeZone.getOffsetNanosecondsFor",
|
|
||||||
// GetInstantFor on preceding midnight
|
|
||||||
"call this.timeZone.getPossibleInstantsFor",
|
|
||||||
// DisambiguatePossibleInstants
|
|
||||||
"call this.timeZone.getOffsetNanosecondsFor",
|
|
||||||
"call this.timeZone.getOffsetNanosecondsFor",
|
|
||||||
"call this.timeZone.getPossibleInstantsFor",
|
|
||||||
// AddZonedDateTime
|
|
||||||
"call this.timeZone.getPossibleInstantsFor",
|
|
||||||
// InterpretISODateTimeOffset
|
|
||||||
"call this.timeZone.getPossibleInstantsFor",
|
|
||||||
"call this.timeZone.getOffsetNanosecondsFor",
|
|
||||||
];
|
|
||||||
|
|
||||||
springForwardInstance.round(options);
|
springForwardInstance.round(options);
|
||||||
assert.compareArray(actual, expectedSkippedDateTime, "order of operations with preceding midnight at skipped wall-clock time");
|
assert.compareArray(actual, expected, "order of operations with preceding midnight at skipped wall-clock time");
|
||||||
actual.splice(0); // clear
|
actual.splice(0); // clear
|
||||||
|
|
||||||
const expectedSkippedResult = [
|
const expectedSkippedResult = [
|
||||||
|
@ -130,14 +98,6 @@ const expectedSkippedResult = [
|
||||||
"get this.timeZone.getPossibleInstantsFor",
|
"get this.timeZone.getPossibleInstantsFor",
|
||||||
// GetPlainDateTimeFor on receiver's instant
|
// GetPlainDateTimeFor on receiver's instant
|
||||||
"call this.timeZone.getOffsetNanosecondsFor",
|
"call this.timeZone.getOffsetNanosecondsFor",
|
||||||
// GetInstantFor on preceding midnight
|
|
||||||
"call this.timeZone.getPossibleInstantsFor",
|
|
||||||
// AddDaysToZonedDateTime
|
|
||||||
"call this.timeZone.getPossibleInstantsFor",
|
|
||||||
// DisambiguatePossibleInstants
|
|
||||||
"call this.timeZone.getOffsetNanosecondsFor",
|
|
||||||
"call this.timeZone.getOffsetNanosecondsFor",
|
|
||||||
"call this.timeZone.getPossibleInstantsFor",
|
|
||||||
// InterpretISODateTimeOffset
|
// InterpretISODateTimeOffset
|
||||||
"call this.timeZone.getPossibleInstantsFor",
|
"call this.timeZone.getPossibleInstantsFor",
|
||||||
// DisambiguatePossibleInstants
|
// DisambiguatePossibleInstants
|
||||||
|
|
|
@ -63,31 +63,32 @@ function test(epochNanoseconds, tomorrowEpochNanoseconds, testCases) {
|
||||||
|
|
||||||
const oneDay = 24n * 60n * 60n * 1000n * 1000n * 1000n;
|
const oneDay = 24n * 60n * 60n * 1000n * 1000n * 1000n;
|
||||||
|
|
||||||
// Test positive divisor (dayLengthNs).
|
|
||||||
test(3n, 10n, {
|
test(3n, 10n, {
|
||||||
ceil: oneDay,
|
ceil: 10n, // end-of-day according to TimeZone protocol
|
||||||
floor: 0n,
|
floor: 0n,
|
||||||
trunc: 0n,
|
trunc: 0n,
|
||||||
halfExpand: 0n,
|
halfExpand: 0n,
|
||||||
});
|
});
|
||||||
|
|
||||||
test(-3n, 10n, {
|
test(-3n, 10n, {
|
||||||
ceil: 0n,
|
ceil: 10n, // end-of-day according to TimeZone protocol
|
||||||
floor: -oneDay,
|
floor: -oneDay,
|
||||||
trunc: -oneDay,
|
trunc: -oneDay,
|
||||||
halfExpand: 0n,
|
halfExpand: 10n, // end-of-day according to TimeZone protocol
|
||||||
});
|
});
|
||||||
|
|
||||||
|
assert.throws(RangeError, () => {
|
||||||
test(-3n, -10n, {
|
test(-3n, -10n, {
|
||||||
ceil: oneDay,
|
ceil: oneDay,
|
||||||
floor: 0n,
|
floor: 0n,
|
||||||
trunc: 0n,
|
trunc: 0n,
|
||||||
halfExpand: 0n,
|
halfExpand: 0n,
|
||||||
});
|
});
|
||||||
|
}, "instant is after TimeZone protocol's end-of-day")
|
||||||
|
|
||||||
// Test values at int64 boundaries.
|
// Test values at int64 boundaries.
|
||||||
test(3n, /*INT64_MAX=*/ 9223372036854775807n, {
|
test(3n, /*INT64_MAX=*/ 9223372036854775807n, {
|
||||||
ceil: oneDay,
|
ceil: /*INT64_MAX=*/ 9223372036854775807n, // end-of-day according to TimeZone protocol
|
||||||
floor: 0n,
|
floor: 0n,
|
||||||
trunc: 0n,
|
trunc: 0n,
|
||||||
halfExpand: 0n,
|
halfExpand: 0n,
|
||||||
|
|
|
@ -22,8 +22,6 @@ features: [Temporal]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
const expected = [
|
const expected = [
|
||||||
"2001-09-09T00:00:00", // called once on midnight of the input datetime
|
|
||||||
"2001-09-10T00:00:00", // called once on the previous value plus one calendar day
|
|
||||||
"2001-09-09T02:00:00", // called once on the rounding result
|
"2001-09-09T02:00:00", // called once on the rounding result
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -216,17 +216,19 @@ var bal = Temporal.ZonedDateTime.from("1976-11-18T23:59:59.999999999+01:00[+01:0
|
||||||
var timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
var timeZone = TemporalHelpers.springForwardFallBackTimeZone();
|
||||||
|
|
||||||
// rounds correctly to a 25-hour day
|
// rounds correctly to a 25-hour day
|
||||||
|
// (the 12.5 hour is the halfway point, which is 11:30 local time, since 2:00-2:59 repeats)
|
||||||
var roundTo = { smallestUnit: "day" };
|
var roundTo = { smallestUnit: "day" };
|
||||||
var roundMeDown = Temporal.PlainDateTime.from("2000-10-29T12:29:59").toZonedDateTime(timeZone);
|
var roundMeDown = Temporal.PlainDateTime.from("2000-10-29T11:29:59").toZonedDateTime(timeZone);
|
||||||
assert.sameValue(`${ roundMeDown.round(roundTo) }`, "2000-10-29T00:00:00-07:00[Custom/Spring_Fall]");
|
assert.sameValue(`${ roundMeDown.round(roundTo) }`, "2000-10-29T00:00:00-07:00[Custom/Spring_Fall]");
|
||||||
var roundMeUp = Temporal.PlainDateTime.from("2000-10-29T12:30:01").toZonedDateTime(timeZone);
|
var roundMeUp = Temporal.PlainDateTime.from("2000-10-29T11:30:01").toZonedDateTime(timeZone);
|
||||||
assert.sameValue(`${ roundMeUp.round(roundTo) }`, "2000-10-30T00:00:00-08:00[Custom/Spring_Fall]");
|
assert.sameValue(`${ roundMeUp.round(roundTo) }`, "2000-10-30T00:00:00-08:00[Custom/Spring_Fall]");
|
||||||
|
|
||||||
// rounds correctly to a 23-hour day
|
// rounds correctly to a 23-hour day
|
||||||
|
// (the 11.5 hour is the halfway point, which is 12:30 local time, since 2:00-2:59 skips)
|
||||||
var roundTo = { smallestUnit: "day" };
|
var roundTo = { smallestUnit: "day" };
|
||||||
var roundMeDown = Temporal.PlainDateTime.from("2000-04-02T11:29:59").toZonedDateTime(timeZone);
|
var roundMeDown = Temporal.PlainDateTime.from("2000-04-02T12:29:59").toZonedDateTime(timeZone);
|
||||||
assert.sameValue(`${ roundMeDown.round(roundTo) }`, "2000-04-02T00:00:00-08:00[Custom/Spring_Fall]");
|
assert.sameValue(`${ roundMeDown.round(roundTo) }`, "2000-04-02T00:00:00-08:00[Custom/Spring_Fall]");
|
||||||
var roundMeUp = Temporal.PlainDateTime.from("2000-04-02T11:30:01").toZonedDateTime(timeZone);
|
var roundMeUp = Temporal.PlainDateTime.from("2000-04-02T12:30:01").toZonedDateTime(timeZone);
|
||||||
assert.sameValue(`${ roundMeUp.round(roundTo) }`, "2000-04-03T00:00:00-07:00[Custom/Spring_Fall]");
|
assert.sameValue(`${ roundMeUp.round(roundTo) }`, "2000-04-03T00:00:00-07:00[Custom/Spring_Fall]");
|
||||||
|
|
||||||
// rounding up to a nonexistent wall-clock time
|
// rounding up to a nonexistent wall-clock time
|
||||||
|
|
Loading…
Reference in New Issue