summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Temporal/Duration/prototype/round/out-of-range-when-adjusting-rounded-days.js
blob: cd6c307e5b149377dd3c1c4d20b22e5154e29d74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.duration.prototype.round
description: >
    When adjusting the rounded days after rounding relative to a ZonedDateTime,
    the duration may go out of range
features: [Temporal]
includes: [temporalHelpers.js]
---*/

// Based on a test case by André Bargull

const d = new Temporal.Duration(0, 0, 0, /* days = */ 1, 0, 0, /* s = */ Number.MAX_SAFE_INTEGER - 86400, 0, 0, /* ns = */ 999_999_999);

const timeZone = new Temporal.TimeZone("UTC");
TemporalHelpers.substituteMethod(timeZone, 'getPossibleInstantsFor', [
  TemporalHelpers.SUBSTITUTE_SKIP,
  [new Temporal.Instant(1n)],
]);

const relativeTo = new Temporal.ZonedDateTime(0n, timeZone);

assert.throws(RangeError, () => d.round({
  largestUnit: 'nanoseconds',
  roundingIncrement: 2,
  relativeTo
}));

reportCompare(0, 0);