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.withplaintime
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.
24 class Shift24Hour extends Temporal.TimeZone {
31 getOffsetNanosecondsFor(instant) {
35 getPossibleInstantsFor(plainDateTime) {
37 const utc = new Temporal.TimeZone("UTC");
38 const [utcInstant] = utc.getPossibleInstantsFor(plainDateTime);
40 utcInstant.subtract({ hours: 12 }),
41 utcInstant.add({ hours: 12 })
46 const timeZone = new Shift24Hour();
48 const instance = new Temporal.ZonedDateTime(0n, timeZone);
49 instance.withPlainTime();
51 assert(calls >= 1, "getPossibleInstantsFor should be called at least once");