Skip to content

Commit 88ad148

Browse files
committed
Intl Era Monthcode: Tests for constraining day in Hebrew leap years
Adds tests for constraining 30 Adar I to 29 Adar when moving from a leap year to a common year, by the add(), subtract(), or with() methods. Constraining of the month code is already tested in leap-months-hebrew.js.
1 parent 3102b7c commit 88ad148

File tree

9 files changed

+300
-0
lines changed

9 files changed

+300
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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: Check constraining days due to leap years (hebrew calendar)
7+
includes: [temporalHelpers.js]
8+
features: [Temporal, Intl.Era-monthcode]
9+
---*/
10+
11+
// Adar I (M05L) has 30 days, and in common years will be constrained to Adar
12+
// (M06) which has 29 days.
13+
// See also leap-months-hebrew.js and constrain-day-hebrew.js.
14+
15+
const calendar = "hebrew";
16+
const options = { overflow: "reject" };
17+
18+
const years1 = new Temporal.Duration(1);
19+
const years1n = new Temporal.Duration(-1);
20+
21+
const adarI = Temporal.PlainDate.from({ year: 5782, monthCode: "M05L", day: 30, calendar }, options);
22+
23+
TemporalHelpers.assertPlainDate(
24+
adarI.add(years1),
25+
5783, 6, "M06", 29, "Adding 1 year to 30 Adar I constrains to 29 Adar",
26+
"am", 5783);
27+
assert.throws(RangeError, function () {
28+
adarI.add(years1, options);
29+
}, "Adding 1 year to 30 Adar I rejects (either because the month or day would be constrained)");
30+
31+
TemporalHelpers.assertPlainDate(
32+
adarI.add(years1n),
33+
5781, 6, "M06", 29, "Subtracting 1 year from 30 Adar I constrains to 29 Adar",
34+
"am", 5781);
35+
assert.throws(RangeError, function () {
36+
adarI.add(years1n, options);
37+
}, "Subtracting 1 year from 30 Adar I rejects (either because the month or day would be constrained)");
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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: Check constraining days due to leap years (hebrew calendar)
7+
includes: [temporalHelpers.js]
8+
features: [Temporal, Intl.Era-monthcode]
9+
---*/
10+
11+
// Adar I (M05L) has 30 days, and in common years will be constrained to Adar
12+
// (M06) which has 29 days.
13+
// See also leap-months-hebrew.js and constrain-day-hebrew.js.
14+
15+
const calendar = "hebrew";
16+
const options = { overflow: "reject" };
17+
18+
const years1 = new Temporal.Duration(-1);
19+
const years1n = new Temporal.Duration(1);
20+
21+
const adarI = Temporal.PlainDate.from({ year: 5782, monthCode: "M05L", day: 30, calendar }, options);
22+
23+
TemporalHelpers.assertPlainDate(
24+
adarI.subtract(years1),
25+
5783, 6, "M06", 29, "Adding 1 year to 30 Adar I constrains to 29 Adar",
26+
"am", 5783);
27+
assert.throws(RangeError, function () {
28+
adarI.subtract(years1, options);
29+
}, "Adding 1 year to 30 Adar I rejects (either because the month or day would be constrained)");
30+
31+
TemporalHelpers.assertPlainDate(
32+
adarI.subtract(years1n),
33+
5781, 6, "M06", 29, "Subtracting 1 year from 30 Adar I constrains to 29 Adar",
34+
"am", 5781);
35+
assert.throws(RangeError, function () {
36+
adarI.subtract(years1n, options);
37+
}, "Subtracting 1 year from 30 Adar I rejects (either because the month or day would be constrained)");
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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.with
6+
description: Check constraining days due to leap years (hebrew calendar)
7+
includes: [temporalHelpers.js]
8+
features: [Temporal, Intl.Era-monthcode]
9+
---*/
10+
11+
// Adar I (M05L) has 30 days, and in common years will be constrained to Adar
12+
// (M06) which has 29 days.
13+
// See also leap-months-hebrew.js and constrain-day-hebrew.js.
14+
15+
const calendar = "hebrew";
16+
const options = { overflow: "reject" };
17+
18+
const adarI = Temporal.PlainDate.from({ year: 5782, monthCode: "M05L", day: 30, calendar }, options);
19+
20+
TemporalHelpers.assertPlainDate(
21+
adarI.with({ year: 5783 }),
22+
5783, 6, "M06", 29, "Changing 30 Adar I to common year constrains to 29 Adar",
23+
"am", 5783);
24+
assert.throws(RangeError, function () {
25+
adarI.with({ year: 5783 }, options);
26+
}, "Changing 30 Adar I to common year rejects (either because the month or day would be constrained)");
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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: Check constraining days due to leap years (hebrew calendar)
7+
includes: [temporalHelpers.js]
8+
features: [Temporal, Intl.Era-monthcode]
9+
---*/
10+
11+
// Adar I (M05L) has 30 days, and in common years will be constrained to Adar
12+
// (M06) which has 29 days.
13+
// See also leap-months-hebrew.js and constrain-day-hebrew.js.
14+
15+
const calendar = "hebrew";
16+
const options = { overflow: "reject" };
17+
18+
const years1 = new Temporal.Duration(1);
19+
const years1n = new Temporal.Duration(-1);
20+
21+
const adarI = Temporal.PlainDateTime.from({ year: 5782, monthCode: "M05L", day: 30, hour: 12, minute: 34, calendar }, options);
22+
23+
TemporalHelpers.assertPlainDateTime(
24+
adarI.add(years1),
25+
5783, 6, "M06", 29, 12, 34, 0, 0, 0, 0, "Adding 1 year to 30 Adar I constrains to 29 Adar",
26+
"am", 5783);
27+
assert.throws(RangeError, function () {
28+
adarI.add(years1, options);
29+
}, "Adding 1 year to 30 Adar I rejects (either because the month or day would be constrained)");
30+
31+
TemporalHelpers.assertPlainDateTime(
32+
adarI.add(years1n),
33+
5781, 6, "M06", 29, 12, 34, 0, 0, 0, 0, "Subtracting 1 year from 30 Adar I constrains to 29 Adar",
34+
"am", 5781);
35+
assert.throws(RangeError, function () {
36+
adarI.add(years1n, options);
37+
}, "Subtracting 1 year from 30 Adar I rejects (either because the month or day would be constrained)");
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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: Check constraining days due to leap years (hebrew calendar)
7+
includes: [temporalHelpers.js]
8+
features: [Temporal, Intl.Era-monthcode]
9+
---*/
10+
11+
// Adar I (M05L) has 30 days, and in common years will be constrained to Adar
12+
// (M06) which has 29 days.
13+
// See also leap-months-hebrew.js and constrain-day-hebrew.js.
14+
15+
const calendar = "hebrew";
16+
const options = { overflow: "reject" };
17+
18+
const years1 = new Temporal.Duration(-1);
19+
const years1n = new Temporal.Duration(1);
20+
21+
const adarI = Temporal.PlainDateTime.from({ year: 5782, monthCode: "M05L", day: 30, hour: 12, minute: 34, calendar }, options);
22+
23+
TemporalHelpers.assertPlainDateTime(
24+
adarI.subtract(years1),
25+
5783, 6, "M06", 29, 12, 34, 0, 0, 0, 0, "Adding 1 year to 30 Adar I constrains to 29 Adar",
26+
"am", 5783);
27+
assert.throws(RangeError, function () {
28+
adarI.subtract(years1, options);
29+
}, "Adding 1 year to 30 Adar I rejects (either because the month or day would be constrained)");
30+
31+
TemporalHelpers.assertPlainDateTime(
32+
adarI.subtract(years1n),
33+
5781, 6, "M06", 29, 12, 34, 0, 0, 0, 0, "Subtracting 1 year from 30 Adar I constrains to 29 Adar",
34+
"am", 5781);
35+
assert.throws(RangeError, function () {
36+
adarI.subtract(years1n, options);
37+
}, "Subtracting 1 year from 30 Adar I rejects (either because the month or day would be constrained)");
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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.with
6+
description: Check constraining days due to leap years (hebrew calendar)
7+
includes: [temporalHelpers.js]
8+
features: [Temporal, Intl.Era-monthcode]
9+
---*/
10+
11+
// Adar I (M05L) has 30 days, and in common years will be constrained to Adar
12+
// (M06) which has 29 days.
13+
// See also leap-months-hebrew.js and constrain-day-hebrew.js.
14+
15+
const calendar = "hebrew";
16+
const options = { overflow: "reject" };
17+
18+
const adarI = Temporal.PlainDateTime.from({ year: 5782, monthCode: "M05L", day: 30, hour: 12, minute: 34, calendar }, options);
19+
20+
TemporalHelpers.assertPlainDateTime(
21+
adarI.with({ year: 5783 }),
22+
5783, 6, "M06", 29, 12, 34, 0, 0, 0, 0,"Changing 30 Adar I to common year constrains to 29 Adar",
23+
"am", 5783);
24+
assert.throws(RangeError, function () {
25+
adarI.with({ year: 5783 }, options);
26+
}, "Changing 30 Adar I to common year rejects (either because the month or day would be constrained)");
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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: Check constraining days due to leap years (hebrew calendar)
7+
includes: [temporalHelpers.js]
8+
features: [Temporal, Intl.Era-monthcode]
9+
---*/
10+
11+
// Adar I (M05L) has 30 days, and in common years will be constrained to Adar
12+
// (M06) which has 29 days.
13+
// See also leap-months-hebrew.js and constrain-day-hebrew.js.
14+
15+
const calendar = "hebrew";
16+
const options = { overflow: "reject" };
17+
18+
const years1 = new Temporal.Duration(1);
19+
const years1n = new Temporal.Duration(-1);
20+
21+
const adarI = Temporal.ZonedDateTime.from({ year: 5782, monthCode: "M05L", day: 30, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
22+
23+
TemporalHelpers.assertPlainDateTime(
24+
adarI.add(years1).toPlainDateTime(),
25+
5783, 6, "M06", 29, 12, 34, 0, 0, 0, 0, "Adding 1 year to 30 Adar I constrains to 29 Adar",
26+
"am", 5783);
27+
assert.throws(RangeError, function () {
28+
adarI.add(years1, options);
29+
}, "Adding 1 year to 30 Adar I rejects (either because the month or day would be constrained)");
30+
31+
TemporalHelpers.assertPlainDateTime(
32+
adarI.add(years1n).toPlainDateTime(),
33+
5781, 6, "M06", 29, 12, 34, 0, 0, 0, 0, "Subtracting 1 year from 30 Adar I constrains to 29 Adar",
34+
"am", 5781);
35+
assert.throws(RangeError, function () {
36+
adarI.add(years1n, options);
37+
}, "Subtracting 1 year from 30 Adar I rejects (either because the month or day would be constrained)");
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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: Check constraining days due to leap years (hebrew calendar)
7+
includes: [temporalHelpers.js]
8+
features: [Temporal, Intl.Era-monthcode]
9+
---*/
10+
11+
// Adar I (M05L) has 30 days, and in common years will be constrained to Adar
12+
// (M06) which has 29 days.
13+
// See also leap-months-hebrew.js and constrain-day-hebrew.js.
14+
15+
const calendar = "hebrew";
16+
const options = { overflow: "reject" };
17+
18+
const years1 = new Temporal.Duration(-1);
19+
const years1n = new Temporal.Duration(1);
20+
21+
const adarI = Temporal.ZonedDateTime.from({ year: 5782, monthCode: "M05L", day: 30, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
22+
23+
TemporalHelpers.assertPlainDateTime(
24+
adarI.subtract(years1).toPlainDateTime(),
25+
5783, 6, "M06", 29, 12, 34, 0, 0, 0, 0, "Adding 1 year to 30 Adar I constrains to 29 Adar",
26+
"am", 5783);
27+
assert.throws(RangeError, function () {
28+
adarI.subtract(years1, options);
29+
}, "Adding 1 year to 30 Adar I rejects (either because the month or day would be constrained)");
30+
31+
TemporalHelpers.assertPlainDateTime(
32+
adarI.subtract(years1n).toPlainDateTime(),
33+
5781, 6, "M06", 29, 12, 34, 0, 0, 0, 0, "Subtracting 1 year from 30 Adar I constrains to 29 Adar",
34+
"am", 5781);
35+
assert.throws(RangeError, function () {
36+
adarI.subtract(years1n, options);
37+
}, "Subtracting 1 year from 30 Adar I rejects (either because the month or day would be constrained)");
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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.with
6+
description: Check constraining days due to leap years (hebrew calendar)
7+
includes: [temporalHelpers.js]
8+
features: [Temporal, Intl.Era-monthcode]
9+
---*/
10+
11+
// Adar I (M05L) has 30 days, and in common years will be constrained to Adar
12+
// (M06) which has 29 days.
13+
// See also leap-months-hebrew.js and constrain-day-hebrew.js.
14+
15+
const calendar = "hebrew";
16+
const options = { overflow: "reject" };
17+
18+
const adarI = Temporal.ZonedDateTime.from({ year: 5782, monthCode: "M05L", day: 30, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
19+
20+
TemporalHelpers.assertPlainDateTime(
21+
adarI.with({ year: 5783 }).toPlainDateTime(),
22+
5783, 6, "M06", 29, 12, 34, 0, 0, 0, 0,"Changing 30 Adar I to common year constrains to 29 Adar",
23+
"am", 5783);
24+
assert.throws(RangeError, function () {
25+
adarI.with({ year: 5783 }, options);
26+
}, "Changing 30 Adar I to common year rejects (either because the month or day would be constrained)");

0 commit comments

Comments
 (0)