Backed out 2 changesets (bug 1888310, bug 1884625) for causing failures on browser_ap...
[gecko.git] / js / src / tests / test262 / built-ins / Temporal / Duration / prototype / add / differencezoneddatetime-inconsistent-custom-calendar.js
blob01bf6c756e5abf73f1dc5374f094ca82ea4eef0a
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.
4 /*---
5 esid: sec-temporal.duration.prototype.add
6 description: >
7   Throws a RangeError when custom calendar method returns inconsistent result
8 info: |
9   DifferenceZonedDateTime ( ... )
10   8. Repeat 3 times:
11     ...
12     g. If _sign_ = 0, or _timeSign_ = 0, or _sign_ = _timeSign_, then
13       ...
14       viii. Return ? CreateNormalizedDurationRecord(_dateDifference_.[[Years]],
15             _dateDifference_.[[Months]], _dateDifference_.[[Weeks]],
16             _dateDifference_.[[Days]], _norm_).
17     h. Set _dayCorrection_ to _dayCorrection_ + 1.
18   9. NOTE: This step is only reached when custom calendar or time zone methods
19      return inconsistent values.
20   10. Throw a *RangeError* exception.
21 features: [Temporal]
22 ---*/
24 // Based partly on a test case by AndrĂ© Bargull
26 const duration1 = new Temporal.Duration(0, 0, /* weeks = */ 7, 0, /* hours = */ 12);
27 const duration2 = new Temporal.Duration(0, 0, 0, /* days = */ 1);
30   const tz = new (class extends Temporal.TimeZone {
31     getPossibleInstantsFor(dateTime) {
32       return super.getPossibleInstantsFor(dateTime.add({ days: 3 }));
33     }
34   })("UTC");
35   
36   const relativeTo = new Temporal.ZonedDateTime(0n, tz);
38   assert.throws(RangeError, () => duration1.add(duration2, { relativeTo }),
39     "Calendar calculation where more than 2 days correction is needed should cause RangeError");
43   const cal = new (class extends Temporal.Calendar {
44     dateUntil(one, two, options) {
45       return super.dateUntil(one, two, options).negated();
46     }
47   })("iso8601");
49   const relativeTo = new Temporal.ZonedDateTime(0n, "UTC", cal);
51   assert.throws(RangeError, () => duration1.add(duration2, { relativeTo }),
52     "Calendar calculation causing mixed-sign values should cause RangeError");
55 reportCompare(0, 0);