Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / Temporal / ZonedDateTime / prototype / startOfDay / getpossibleinstantsfor-maximum-backward-offset-shift.js
blobf1342dfe2dad96dc4a65e58c3f1e44d026406832
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.startofday
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 let calls = 0;
24 class Shift24Hour extends Temporal.TimeZone {
25   id = 'TestTimeZone';
27   constructor() {
28     super('UTC');
29   }
31   getOffsetNanosecondsFor(instant) {
32     return 0;
33   }
35   getPossibleInstantsFor(plainDateTime) {
36     calls++;
37     const utc = new Temporal.TimeZone("UTC");
38     const [utcInstant] = utc.getPossibleInstantsFor(plainDateTime);
39     return [
40       utcInstant.subtract({ hours: 12 }),
41       utcInstant.add({ hours: 12 })
42     ];
43   }
46 const timeZone = new Shift24Hour();
48 const instance = new Temporal.ZonedDateTime(0n, timeZone);
49 instance.startOfDay();
50   
51 assert(calls >= 1, "getPossibleInstantsFor should be called at least once");
53 reportCompare(0, 0);