Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / Temporal / ZonedDateTime / prototype / withPlainDate / getpossibleinstantsfor-out-of-range-backward-offset-shift.js
blobb43bdba30046a5968c601643e48b31d7835aa60b
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.
5 /*---
6 esid: sec-temporal.zoneddatetime.prototype.withplaindate
7 description: >
8   UTC offset shift returned by getPossibleInstantsFor can be at most 24 hours.
9 features: [Temporal]
10 info: |
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.
20 ---*/
22 class ShiftLonger24Hour extends Temporal.TimeZone {
23   id = 'TestTimeZone';
25   constructor() {
26     super('UTC');
27   }
29   getOffsetNanosecondsFor(instant) {
30     return 0;
31   }
33   getPossibleInstantsFor(plainDateTime) {
34     const utc = new Temporal.TimeZone("UTC");
35     const [utcInstant] = utc.getPossibleInstantsFor(plainDateTime);
36     return [
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
40     ];
41   }
44 const timeZone = new ShiftLonger24Hour();
46 const instance = new Temporal.ZonedDateTime(0n, timeZone);
47 assert.throws(RangeError, () => instance.withPlainDate(new Temporal.PlainDate(1970, 1, 1)), "RangeError should be thrown");
49 reportCompare(0, 0);