mirror of
https://github.com/tc39/test262.git
synced 2025-11-16 11:49:45 +01:00
Adapts the tests that checked arbitrarily long loops, to now check that an exception is thrown if the loop would happen. Adds tests that exercise the newly added checks on return values of getPossibleInstantsFor and getOffsetNanosecondsFor that limit UTC offset shifts to 24 hours or less. Also updates some step numbers in related tests.
44 lines
1.6 KiB
JavaScript
44 lines
1.6 KiB
JavaScript
// 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.compare
|
|
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 arg = { year: 1970, month: 1, day: 1, hour: 12, timeZone };
|
|
const datetime = new Temporal.ZonedDateTime(0n, timeZone);
|
|
|
|
assert.throws(RangeError, () => Temporal.ZonedDateTime.compare(arg, datetime), "RangeError should be thrown (first argument)");
|
|
assert.throws(RangeError, () => Temporal.ZonedDateTime.compare(datetime, arg), "RangeError should be thrown (second argument)");
|