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