Skip to content

Commit 61d0eb9

Browse files
authored
Temporal: Add an overflow test for date addition with maximum year (#4618)
* Temporal: Add an overflow test for date addition with maximum year * Add tests for other cases * Fix minimum dates * Add cases for adding/subtracting the negated duration to the opposite end of the allowed years
1 parent 759fe87 commit 61d0eb9

File tree

8 files changed

+120
-0
lines changed

8 files changed

+120
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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.plaindate.prototype.add
6+
description: Adding months to maximum year should throw
7+
features: [Temporal]
8+
---*/
9+
10+
const maxYear = new Temporal.PlainDate(275760, 1, 1);
11+
const duration = new Temporal.Duration(0, 5432, 5432, 0, 0, 0, 0, 0, 0, 0);
12+
assert.throws(RangeError, () => maxYear.add(duration));
13+
14+
const minYear = new Temporal.PlainDate(-271821, 4, 19);
15+
assert.throws(RangeError, () => minYear.add(duration.negated()));
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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.plaindate.prototype.subtract
6+
description: Subtracting months from minimum year should throw
7+
features: [Temporal]
8+
---*/
9+
10+
const minYear = new Temporal.PlainDate(-271821, 4, 19);
11+
const duration = new Temporal.Duration(0, 5432, 5432, 0, 0, 0, 0, 0, 0, 0);
12+
assert.throws(RangeError, () => minYear.subtract(duration));
13+
14+
const maxYear = new Temporal.PlainDate(275760, 1, 1);
15+
assert.throws(RangeError, () => maxYear.subtract(duration.negated()));
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 months to maximum year should throw
7+
features: [Temporal]
8+
---*/
9+
10+
const maxYear = new Temporal.PlainDateTime(275760, 1, 1);
11+
const duration = new Temporal.Duration(0, 5432, 5432, 0, 0, 0, 0, 0, 0, 0);
12+
assert.throws(RangeError, () => maxYear.add(duration));
13+
14+
const minYear = new Temporal.PlainDateTime(-271821, 4, 19, 0, 0, 0, 0, 0, 1);
15+
assert.throws(RangeError, () => minYear.add(duration.negated()));
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 months from minimum year should throw
7+
features: [Temporal]
8+
---*/
9+
10+
const minYear = new Temporal.PlainDateTime(-271821, 4, 19, 0, 0, 0, 0, 0, 1);
11+
const duration = new Temporal.Duration(0, 5432, 5432, 0, 0, 0, 0, 0, 0, 0);
12+
assert.throws(RangeError, () => minYear.subtract(duration));
13+
14+
const maxYear = new Temporal.PlainDateTime(275760, 1, 1);
15+
assert.throws(RangeError, () => maxYear.subtract(duration.negated()));
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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.plainyearmonth.prototype.add
6+
description: Adding months to maximum year should throw
7+
features: [Temporal]
8+
---*/
9+
10+
const maxYear = new Temporal.PlainYearMonth(275760, 1);
11+
const duration = new Temporal.Duration(0, 5432, 5432, 0, 0, 0, 0, 0, 0, 0);
12+
assert.throws(RangeError, () => maxYear.add(duration));
13+
14+
const minYear = new Temporal.PlainYearMonth(-271821, 4);
15+
assert.throws(RangeError, () => minYear.add(duration.negated()));
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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.plainyearmonth.prototype.subtract
6+
description: Subtracting months from minimum year should throw
7+
features: [Temporal]
8+
---*/
9+
10+
const minYear = new Temporal.PlainYearMonth(-271821, 4);
11+
const duration = new Temporal.Duration(0, 5432, 5432, 0, 0, 0, 0, 0, 0, 0);
12+
assert.throws(RangeError, () => minYear.subtract(duration));
13+
14+
const maxYear = new Temporal.PlainYearMonth(275760, 1);
15+
assert.throws(RangeError, () => maxYear.subtract(duration.negated()));
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 months to maximum year should throw
7+
features: [Temporal]
8+
---*/
9+
10+
const maxYear = new Temporal.PlainDate(275760, 1, 1).toZonedDateTime("UTC");
11+
const duration = new Temporal.Duration(0, 5432, 5432, 0, 0, 0, 0, 0, 0, 0);
12+
assert.throws(RangeError, () => maxYear.add(duration));
13+
14+
const minYear = new Temporal.ZonedDateTime(-(864n * 10n ** 19n), "UTC");
15+
assert.throws(RangeError, () => minYear.add(duration.negated()));
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 months from minimum year should throw
7+
features: [Temporal]
8+
---*/
9+
10+
const minYear = new Temporal.ZonedDateTime(-(864n * 10n ** 19n), "UTC");
11+
const duration = new Temporal.Duration(0, 5432, 5432, 0, 0, 0, 0, 0, 0, 0);
12+
assert.throws(RangeError, () => minYear.subtract(duration));
13+
14+
const maxYear = new Temporal.PlainDateTime(275760, 1, 1).toZonedDateTime("UTC");
15+
assert.throws(RangeError, () => maxYear.subtract(duration.negated()));

0 commit comments

Comments
 (0)