test262/test/built-ins/Temporal/Duration/compare/throws-when-target-zoned-date-time-outside-valid-limits.js
2025-01-09 16:33:51 -08:00

33 lines
1.1 KiB
JavaScript

// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.duration.compare
description: >
Throws RangeError when adding duration to ZonedDateTime relativeTo fails.
info: |
Temporal.Duration.compare ( one, two [ , options ] )
12. If zonedRelativeTo is not undefined, and either TemporalUnitCategory(largestUnit1)
or TemporalUnitCategory(largestUnit2) is date, then
...
c. Let after1 be ? AddZonedDateTime(zonedRelativeTo.[[EpochNanoseconds]], timeZone,
calendar, duration1, constrain).
d. Let after2 be ? AddZonedDateTime(zonedRelativeTo.[[EpochNanoseconds]], timeZone,
calendar, duration2, constrain).
...
features: [Temporal]
---*/
var blank = new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
var oneDay = new Temporal.Duration(0, 0, 0, 1);
var relativeTo = new Temporal.ZonedDateTime(864n * 10n**19n, "UTC");
var options = {
relativeTo
};
assert.throws(RangeError, () => Temporal.Duration.compare(oneDay, blank, options));
assert.throws(RangeError, () => Temporal.Duration.compare(blank, oneDay, options));