Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / Temporal / Duration / prototype / subtract / relativeto-propertybag-out-of-range-forward-offset-shift.js
blob3d1d6262f03415a3075179f9641f2658c7eb3ec7
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.duration.prototype.subtract
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();
40 const relativeTo = { year: 1970, month: 1, day: 1, hour: 12, timeZone };
42 const instance = new Temporal.Duration(1, 0, 0, 1);
43 assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), "RangeError should be thrown");
45 reportCompare(0, 0);