Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / Temporal / ZonedDateTime / prototype / with / getoffsetnanosecondsfor-maximum-forward-offset-shift.js
bloba1c2cec71d5109b506642006e85d8715f288dbb1
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.with
7 description: >
8   UTC offset shift returned by adjacent invocations of getOffsetNanosecondsFor
9   in DisambiguatePossibleInstants can be at most 24 hours.
10 features: [Temporal]
11 info: |
12   DisambiguatePossibleInstants:
13   18. If abs(_nanoseconds_) > nsPerDay, throw a *RangeError* exception.
14 ---*/
16 let calls = 0;
18 class Shift24Hour extends Temporal.TimeZone {
19   id = 'TestTimeZone';
20   _shiftEpochNs = 0n;
22   constructor() {
23     super('UTC');
24   }
26   getOffsetNanosecondsFor(instant) {
27     calls++;
28     if (instant.epochNanoseconds < this._shiftEpochNs) return -12 * 3600e9;
29     return 12 * 3600e9;
30   }
32   getPossibleInstantsFor(plainDateTime) {
33     const [utcInstant] = super.getPossibleInstantsFor(plainDateTime);
34     const { year, month, day } = plainDateTime;
36     if (year < 1970) return [utcInstant.subtract({ hours: 12 })];
37     if (year === 1970 && month === 1 && day === 1) return [];
38     return [utcInstant.add({ hours: 12 })];
39   }
42 const timeZone = new Shift24Hour();
43 const instance = new Temporal.ZonedDateTime(0n, timeZone);
45 for (const disambiguation of ["earlier", "later", "compatible"]) {
46   instance.with({ day: 1 }, { disambiguation });
48   assert(calls >= 2, "getOffsetNanosecondsFor should be called at least twice");
49   calls = 0;
52 reportCompare(0, 0);