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.duration.prototype.subtract
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();
40 const relativeTo = { year: 1970, month: 1, day: 1, hour: 12, timeZone };
42 const instance = new Temporal.Duration(1, 0, 0, 1);
43 assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), "RangeError should be thrown");