1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
2 // Copyright (C) 2024 Igalia, S.L. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
6 esid: sec-temporal.timezone.prototype.getinstantfor
8 UTC offset shift returned by adjacent invocations of getOffsetNanosecondsFor
9 in DisambiguatePossibleInstants cannot be greater than 24 hours.
12 DisambiguatePossibleInstants:
13 18. If abs(_nanoseconds_) > nsPerDay, throw a *RangeError* exception.
16 class ShiftLonger24Hour extends Temporal.TimeZone {
18 _shiftEpochNs = 12n * 3600n * 1_000_000_000n; // 1970-01-01T12:00Z
24 getOffsetNanosecondsFor(instant) {
25 if (instant.epochNanoseconds < this._shiftEpochNs) return -12 * 3600e9;
26 return 12 * 3600e9 + 1;
29 getPossibleInstantsFor(plainDateTime) {
30 const [utcInstant] = super.getPossibleInstantsFor(plainDateTime);
31 const { year, month, day } = plainDateTime;
33 if (year < 1970) return [utcInstant.subtract({ hours: 12 })];
34 if (year === 1970 && month === 1 && day === 1) return [];
35 return [utcInstant.add({ hours: 12, nanoseconds: 1 })];
39 const timeZone = new ShiftLonger24Hour();
41 for (const disambiguation of ["earlier", "later", "compatible"]) {
42 assert.throws(RangeError, () => timeZone.getInstantFor(new Temporal.PlainDateTime(1970, 1, 1, 12), { disambiguation }), "RangeError should be thrown");