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.equals
8 UTC offset shift returned by getPossibleInstantsFor can be at most 24 hours.
11 GetPossibleInstantsFor:
12 5.b.i. Let _numResults_ be _list_'s length.
13 ii. If _numResults_ > 1, then
14 1. Let _epochNs_ be a new empty List.
15 2. For each value _instant_ in list, do
16 a. Append _instant_.[[EpochNanoseconds]] to the end of the List _epochNs_.
17 3. Let _min_ be the least element of the List _epochNs_.
18 4. Let _max_ be the greatest element of the List _epochNs_.
19 5. If abs(ℝ(_max_ - _min_)) > nsPerDay, throw a *RangeError* exception.
22 class ShiftLonger24Hour extends Temporal.TimeZone {
29 getOffsetNanosecondsFor(instant) {
33 getPossibleInstantsFor(plainDateTime) {
34 const utc = new Temporal.TimeZone("UTC");
35 const [utcInstant] = utc.getPossibleInstantsFor(plainDateTime);
37 utcInstant.subtract({ hours: 12, nanoseconds: 1 }),
38 utcInstant.add({ hours: 12 }),
39 utcInstant, // add a third value in case the implementation doesn't sort
44 const timeZone = new ShiftLonger24Hour();
45 const arg = { year: 1970, month: 1, day: 1, hour: 12, timeZone };
47 const instance = new Temporal.ZonedDateTime(0n, timeZone);
48 assert.throws(RangeError, () => instance.equals(arg), "RangeError should be thrown");