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.zoneddatetime.prototype.with
8 UTC offset shift returned by adjacent invocations of getOffsetNanosecondsFor
9 in DisambiguatePossibleInstants can be at most 24 hours.
12 DisambiguatePossibleInstants:
13 18. If abs(_nanoseconds_) > nsPerDay, throw a *RangeError* exception.
18 class Shift24Hour extends Temporal.TimeZone {
26 getOffsetNanosecondsFor(instant) {
28 if (instant.epochNanoseconds < this._shiftEpochNs) return -12 * 3600e9;
32 getPossibleInstantsFor(plainDateTime) {
33 const [utcInstant] = super.getPossibleInstantsFor(plainDateTime);
34 const { year, month, day } = plainDateTime;
36 if (year < 1970) return [utcInstant.subtract({ hours: 12 })];
37 if (year === 1970 && month === 1 && day === 1) return [];
38 return [utcInstant.add({ hours: 12 })];
42 const timeZone = new Shift24Hour();
43 const instance = new Temporal.ZonedDateTime(0n, timeZone);
45 for (const disambiguation of ["earlier", "later", "compatible"]) {
46 instance.with({ day: 1 }, { disambiguation });
48 assert(calls >= 2, "getOffsetNanosecondsFor should be called at least twice");