| 1 |
// |reftest| shell-option(--enable-temporal) skip-if(!this.hasOwnProperty('Temporal')||!xulRuntime.shell) -- Temporal is not enabled unconditionally, requires shell-options |
| 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 |
/*--- |
| 6 |
esid: sec-temporal.duration.compare |
| 7 |
description: RangeError thrown when calendar part of duration added to relativeTo is out of range |
| 8 |
features: [Temporal] |
| 9 |
info: | |
| 10 |
UnbalanceDateDurationRelative: |
| 11 |
11. Let _yearsMonthsWeeksDuration_ be ! CreateTemporalDuration(_years_, _months_, _weeks_, 0, 0, 0, 0, 0, 0, 0). |
| 12 |
12. Let _later_ be ? CalendarDateAdd(_calendaRec_, _plainRelativeTo_, _yearsMonthsWeeksDuration_). |
| 13 |
13. Let _yearsMonthsWeeksInDays_ be DaysUntil(_plainRelativeTo_, _later_). |
| 14 |
14. Return ? CreateDateDurationRecord(0, 0, 0, _days_ + _yearsMonthsWeeksInDays_). |
| 15 |
---*/ |
| 16 |
|
| 17 |
// Based on a test case by André Bargull <[email protected]> |
| 18 |
|
| 19 |
const relativeTo = new Temporal.PlainDate(2000, 1, 1); |
| 20 |
const zero = new Temporal.Duration(); |
| 21 |
|
| 22 |
const instance = new Temporal.Duration(0, 0, /* weeks = */ 1, /* days = */ Math.trunc((2 ** 53) / 86_400)); |
| 23 |
assert.throws(RangeError, () => Temporal.Duration.compare(instance, zero, {relativeTo}), "weeks + days out of range, positive, first argument"); |
| 24 |
assert.throws(RangeError, () => Temporal.Duration.compare(zero, instance, {relativeTo}), "weeks + days out of range, positive, second argument"); |
| 25 |
|
| 26 |
const negInstance = new Temporal.Duration(0, 0, /* weeks = */ -1, /* days = */ -Math.trunc((2 ** 53) / 86_400)); |
| 27 |
assert.throws(RangeError, () => Temporal.Duration.compare(negInstance, zero, {relativeTo}), "weeks + days out of range, negative, first argument"); |
| 28 |
assert.throws(RangeError, () => Temporal.Duration.compare(zero, negInstance, {relativeTo}), "weeks + days out of range, negative, second argument"); |
| 29 |
|
| 30 |
reportCompare(0, 0); |