Skip to content

Commit 759fe87

Browse files
catamorphismptomato
authored andcommitted
Temporal: Add coverage for adding large microseconds/nanoseconds values
Add coverage for adding unbalanced durations with large microseconds or nanoseconds values to a PlainDateTime or ZonedDateTime.
1 parent c588df6 commit 759fe87

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.plaindatetime.prototype.add
6+
description: Adding unbalanced durations with large subsecond values to a date
7+
includes: [temporalHelpers.js]
8+
features: [Temporal]
9+
---*/
10+
11+
const pdt = new Temporal.PlainDateTime(2020, 2, 29, 0, 57, 27, 747, 612, 578);
12+
TemporalHelpers.assertPlainDateTime(pdt.add(Temporal.Duration.from({nanoseconds: Number.MAX_SAFE_INTEGER})),
13+
2020, 6, "M06", 12, 6, 57, 27, 2, 353, 569);
14+
TemporalHelpers.assertPlainDateTime(pdt.add(Temporal.Duration.from({microseconds: Number.MAX_SAFE_INTEGER})),
15+
2305, 8, "M08", 4, 0, 45, 2, 488, 603, 578);
16+
assert.throws(RangeError, () => pdt.add(Temporal.Duration.from({milliseconds: Number.MAX_SAFE_INTEGER})));
17+
assert.throws(RangeError, () => pdt.add(Temporal.Duration.from({seconds: Number.MAX_SAFE_INTEGER})));
18+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.plaindatetime.prototype.subtract
6+
description: Subtracting unbalanced durations with large subsecond values from a date
7+
includes: [temporalHelpers.js]
8+
features: [Temporal]
9+
---*/
10+
11+
const pdt = new Temporal.PlainDateTime(2020, 2, 29, 0, 57, 27, 747, 612, 578);
12+
TemporalHelpers.assertPlainDateTime(pdt.subtract(Temporal.Duration.from({nanoseconds: Number.MAX_SAFE_INTEGER})),
13+
2019, 11, "M11", 16, 18, 57, 28, 492, 871, 587);
14+
TemporalHelpers.assertPlainDateTime(pdt.subtract(Temporal.Duration.from({microseconds: Number.MAX_SAFE_INTEGER})),
15+
1734, 9, "M09", 26, 1, 9, 53, 6, 621, 578);
16+
assert.throws(RangeError, () => pdt.subtract(Temporal.Duration.from({milliseconds: Number.MAX_SAFE_INTEGER})));
17+
assert.throws(RangeError, () => pdt.subtract(Temporal.Duration.from({seconds: Number.MAX_SAFE_INTEGER})));
18+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.zoneddatetime.prototype.add
6+
description: Adding unbalanced durations with large subsecond values to a date
7+
includes: [temporalHelpers.js]
8+
features: [Temporal]
9+
---*/
10+
11+
// const pdt = new Temporal.PlainDateTime(2020, 2, 29, 0, 57, 27, 747, 612, 578);
12+
const zdt = new Temporal.ZonedDateTime(1582966647747612578n, "America/Los_Angeles");
13+
14+
TemporalHelpers.assertZonedDateTimesEqual(zdt.add(Temporal.Duration.from({nanoseconds: Number.MAX_SAFE_INTEGER})),
15+
new Temporal.ZonedDateTime(1591973847002353569n, "America/Los_Angeles"));
16+
TemporalHelpers.assertZonedDateTimesEqual(zdt.add(Temporal.Duration.from({microseconds: Number.MAX_SAFE_INTEGER})),
17+
new Temporal.ZonedDateTime(10590165902488603578n, "America/Los_Angeles"));
18+
assert.throws(RangeError, () => zdt.add(Temporal.Duration.from({milliseconds: Number.MAX_SAFE_INTEGER})));
19+
assert.throws(RangeError, () => zdt.add(Temporal.Duration.from({seconds: Number.MAX_SAFE_INTEGER})));
20+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.zoneddatetime.prototype.subtract
6+
description: Subtracting unbalanced durations with large subsecond values from a date
7+
includes: [temporalHelpers.js]
8+
features: [Temporal]
9+
---*/
10+
11+
// const pdt = new Temporal.PlainDateTime(2020, 2, 29, 0, 57, 27, 747, 612, 578);
12+
const zdt = new Temporal.ZonedDateTime(1582966647747612578n, "America/Los_Angeles");
13+
14+
TemporalHelpers.assertZonedDateTimesEqual(zdt.subtract(Temporal.Duration.from({nanoseconds: Number.MAX_SAFE_INTEGER})),
15+
new Temporal.ZonedDateTime(1573959448492871587n, "America/Los_Angeles"));
16+
TemporalHelpers.assertZonedDateTimesEqual(zdt.subtract(Temporal.Duration.from({microseconds: Number.MAX_SAFE_INTEGER})),
17+
new Temporal.ZonedDateTime(-7424232606993378422n, "America/Los_Angeles"));
18+
assert.throws(RangeError, () => zdt.subtract(Temporal.Duration.from({milliseconds: Number.MAX_SAFE_INTEGER})));
19+
assert.throws(RangeError, () => zdt.subtract(Temporal.Duration.from({seconds: Number.MAX_SAFE_INTEGER})));
20+

0 commit comments

Comments
 (0)