Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / Temporal / TimeZone / prototype / getInstantFor / getoffsetnanosecondsfor-out-of-range-forward-offset-shift.js
blob020151a0d8b201d25f3c1794b9821054ae72edf6
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.timezone.prototype.getinstantfor
7 description: >
8   UTC offset shift returned by adjacent invocations of getOffsetNanosecondsFor
9   in DisambiguatePossibleInstants cannot be greater than 24 hours.
10 features: [Temporal]
11 info: |
12   DisambiguatePossibleInstants:
13   18. If abs(_nanoseconds_) > nsPerDay, throw a *RangeError* exception.
14 ---*/
16 class ShiftLonger24Hour extends Temporal.TimeZone {
17   id = 'TestTimeZone';
18   _shiftEpochNs = 12n * 3600n * 1_000_000_000n; // 1970-01-01T12:00Z
20   constructor() {
21     super('UTC');
22   }
24   getOffsetNanosecondsFor(instant) {
25     if (instant.epochNanoseconds < this._shiftEpochNs) return -12 * 3600e9;
26     return 12 * 3600e9 + 1;
27   }
29   getPossibleInstantsFor(plainDateTime) {
30     const [utcInstant] = super.getPossibleInstantsFor(plainDateTime);
31     const { year, month, day } = plainDateTime;
33     if (year < 1970) return [utcInstant.subtract({ hours: 12 })];
34     if (year === 1970 && month === 1 && day === 1) return [];
35     return [utcInstant.add({ hours: 12, nanoseconds: 1 })];
36   }
39 const timeZone = new ShiftLonger24Hour();
41 for (const disambiguation of ["earlier", "later", "compatible"]) {
42   assert.throws(RangeError, () => timeZone.getInstantFor(new Temporal.PlainDateTime(1970, 1, 1, 12), { disambiguation }), "RangeError should be thrown");
46 reportCompare(0, 0);