Skip to content

Commit e9efc1b

Browse files
committed
Intl Era Monthcode: Test constraining day at end of Hebrew months
This adds tests for constraining the day when adding years and months in the Hebrew calendars. Test that 30 gets constrained to 29 in 29-day months. There are special test cases for the variable lengths of Cheshvan (M02) and Kislev (M03).
1 parent 88ad148 commit e9efc1b

File tree

9 files changed

+3888
-0
lines changed

9 files changed

+3888
-0
lines changed

test/intl402/Temporal/PlainDate/prototype/add/constrain-day-hebrew.js

Lines changed: 520 additions & 0 deletions
Large diffs are not rendered by default.

test/intl402/Temporal/PlainDate/prototype/subtract/constrain-day-hebrew.js

Lines changed: 520 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
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: Constraining the day at end of month (hebrew calendar)
7+
includes: [temporalHelpers.js]
8+
features: [Temporal, Intl.Era-monthcode]
9+
---*/
10+
11+
const calendar = "hebrew";
12+
const options = { overflow: "reject" };
13+
14+
// 30-day months: 01, 05, 05L, 07, 09, 11
15+
// 29-day months: 04, 06, 08, 10, 12
16+
//
17+
// Cheshvan and Kislev (02, 03) have 29 or 30 days, independent of leap years.
18+
// Deficient - Cheshvan and Kislev have 29 days
19+
// Regular - Cheshvan has 29 days, Kislev 30
20+
// Complete - Cheshvan and Kislev have 30 days
21+
//
22+
// Some recent years of each type:
23+
// 5778 - regular common year
24+
// 5779 - complete leap year
25+
// 5781 - deficient common year
26+
// 5782 - regular leap year
27+
// 5783 - complete common year
28+
// 5784 - deficient leap year
29+
30+
// Years
31+
32+
const rcM03 = Temporal.PlainDate.from({ year: 5778, monthCode: "M03", day: 30, calendar }, options);
33+
const clM02 = Temporal.PlainDate.from({ year: 5779, monthCode: "M02", day: 30, calendar }, options);
34+
const clM03 = Temporal.PlainDate.from({ year: 5779, monthCode: "M03", day: 30, calendar }, options);
35+
36+
TemporalHelpers.assertPlainDate(
37+
rcM03.with({ year: 5781 }),
38+
5781, 3, "M03", 29, "regular-year Kislev constrains to 29 in deficient year",
39+
"am", 5781);
40+
assert.throws(RangeError, function () {
41+
rcM03.with({ year: 5781 }, options);
42+
}, "regular-year Kislev rejects 30 in deficient year");
43+
44+
TemporalHelpers.assertPlainDate(
45+
clM02.with({ year: 5782 }),
46+
5782, 2, "M02", 29, "complete-year Cheshvan constrains to 29 in regular year",
47+
"am", 5782);
48+
assert.throws(RangeError, function () {
49+
clM02.with({ year: 5782 }, options);
50+
}, "complete-year Cheshvan rejects 30 in regular year");
51+
52+
TemporalHelpers.assertPlainDate(
53+
clM02.with({ year: 5781 }),
54+
5781, 2, "M02", 29, "complete-year Cheshvan constrains to 29 in deficient year",
55+
"am", 5781);
56+
assert.throws(RangeError, function () {
57+
clM02.with({ year: 5781 }, options);
58+
}, "complete-year Cheshvan rejects 30 in deficient year");
59+
60+
TemporalHelpers.assertPlainDate(
61+
clM03.with({ year: 5781 }),
62+
5781, 3, "M03", 29, "complete-year Kislev constrains to 29 in deficient year",
63+
"am", 5781);
64+
assert.throws(RangeError, function () {
65+
clM03.with({ year: 5781 }, options);
66+
}, "complete-year Kislev rejects 30 in deficient year");
67+
68+
// Months
69+
70+
const dc0130 = Temporal.PlainDate.from({ year: 5781, monthCode: "M01", day: 30, calendar }, options);
71+
const rc0130 = Temporal.PlainDate.from({ year: 5778, monthCode: "M01", day: 30, calendar }, options);
72+
const cc0130 = Temporal.PlainDate.from({ year: 5783, monthCode: "M01", day: 30, calendar }, options);
73+
const dl0130 = Temporal.PlainDate.from({ year: 5784, monthCode: "M01", day: 30, calendar }, options);
74+
const rl0130 = Temporal.PlainDate.from({ year: 5782, monthCode: "M01", day: 30, calendar }, options);
75+
const cl0130 = Temporal.PlainDate.from({ year: 5779, monthCode: "M01", day: 30, calendar }, options);
76+
77+
// Common year
78+
79+
TemporalHelpers.assertPlainDate(
80+
rc0130.with({ monthCode: "M02" }),
81+
5778, 2, "M02", 29, "regular common year Cheshvan constrains to 29",
82+
"am", 5778);
83+
assert.throws(RangeError, function () {
84+
rc0130.with({ monthCode: "M02" }, options);
85+
}, "regular common year Cheshvan rejects 30");
86+
87+
TemporalHelpers.assertPlainDate(
88+
cc0130.with({ monthCode: "M02" }),
89+
5783, 2, "M02", 30, "regular common year Cheshvan does not reject 30",
90+
"am", 5783);
91+
92+
TemporalHelpers.assertPlainDate(
93+
rc0130.with({ monthCode: "M03" }),
94+
5778, 3, "M03", 30, "regular common year Kislev does not reject 30",
95+
"am", 5778);
96+
97+
TemporalHelpers.assertPlainDate(
98+
dc0130.with({ monthCode: "M03" }),
99+
5781, 3, "M03", 29, "deficient common year Kislev constrains to 29",
100+
"am", 5781);
101+
assert.throws(RangeError, function () {
102+
dc0130.with({ monthCode: "M03" }, options);
103+
}, "deficient common year Kislev rejects 30");
104+
105+
TemporalHelpers.assertPlainDate(
106+
rc0130.with({ monthCode: "M04" }),
107+
5778, 4, "M04", 29, "common-year Tevet constrains to 29",
108+
"am", 5778);
109+
assert.throws(RangeError, function () {
110+
rc0130.with({ monthCode: "M04" }, options);
111+
}, "common-year Tevet rejects 30");
112+
113+
TemporalHelpers.assertPlainDate(
114+
rc0130.with({ monthCode: "M05" }),
115+
5778, 5, "M05", 30, "common-year Shevat does not reject 30",
116+
"am", 5778);
117+
118+
TemporalHelpers.assertPlainDate(
119+
rc0130.with({ monthCode: "M06" }),
120+
5778, 6, "M06", 29, "common-year Adar constrains to 29",
121+
"am", 5778);
122+
assert.throws(RangeError, function () {
123+
rc0130.with({ monthCode: "M06" }, options);
124+
}, "common-year Adar rejects 30");
125+
126+
TemporalHelpers.assertPlainDate(
127+
rc0130.with({ monthCode: "M07" }),
128+
5778, 7, "M07", 30, "common-year Nisan does not reject 30",
129+
"am", 5778);
130+
131+
TemporalHelpers.assertPlainDate(
132+
rc0130.with({ monthCode: "M08" }),
133+
5778, 8, "M08", 29, "common-year Iyar constrains to 29",
134+
"am", 5778);
135+
assert.throws(RangeError, function () {
136+
rc0130.with({ monthCode: "M08" }, options);
137+
}, "common-year Iyar rejects 30");
138+
139+
TemporalHelpers.assertPlainDate(
140+
rc0130.with({ monthCode: "M09" }),
141+
5778, 9, "M09", 30, "common-year Sivan does not reject 30",
142+
"am", 5778);
143+
144+
TemporalHelpers.assertPlainDate(
145+
rc0130.with({ monthCode: "M10" }),
146+
5778, 10, "M10", 29, "common-year Tammuz constrains to 29",
147+
"am", 5778);
148+
assert.throws(RangeError, function () {
149+
rc0130.with({ monthCode: "M10" }, options);
150+
}, "common-year Tammuz rejects 30");
151+
152+
TemporalHelpers.assertPlainDate(
153+
rc0130.with({ monthCode: "M11" }),
154+
5778, 11, "M11", 30, "common-year Av does not reject 30",
155+
"am", 5778);
156+
157+
TemporalHelpers.assertPlainDate(
158+
rc0130.with({ monthCode: "M12" }),
159+
5778, 12, "M12", 29, "common-year Elul constrains to 29",
160+
"am", 5778);
161+
assert.throws(RangeError, function () {
162+
rc0130.with({ monthCode: "M12" }, options);
163+
}, "common-year Elul rejects 30");
164+
165+
// Leap year
166+
167+
TemporalHelpers.assertPlainDate(
168+
rl0130.with({ monthCode: "M02" }),
169+
5782, 2, "M02", 29, "regular leap year Cheshvan constrains to 29",
170+
"am", 5782);
171+
assert.throws(RangeError, function () {
172+
rl0130.with({ monthCode: "M02" }, options);
173+
}, "regular leap year Cheshvan rejects 30");
174+
175+
TemporalHelpers.assertPlainDate(
176+
cl0130.with({ monthCode: "M02" }),
177+
5779, 2, "M02", 30, "regular leap year Cheshvan does not reject 30",
178+
"am", 5779);
179+
180+
TemporalHelpers.assertPlainDate(
181+
rl0130.with({ monthCode: "M03" }),
182+
5782, 3, "M03", 30, "regular leap year Kislev does not reject 30",
183+
"am", 5782);
184+
185+
TemporalHelpers.assertPlainDate(
186+
dl0130.with({ monthCode: "M03" }),
187+
5784, 3, "M03", 29, "deficient leap year Kislev constrains to 29",
188+
"am", 5784);
189+
assert.throws(RangeError, function () {
190+
dl0130.with({ monthCode: "M03" }, options);
191+
}, "deficient leap year Kislev rejects 30");
192+
193+
TemporalHelpers.assertPlainDate(
194+
rl0130.with({ monthCode: "M04" }),
195+
5782, 4, "M04", 29, "leap-year Tevet constrains to 29",
196+
"am", 5782);
197+
assert.throws(RangeError, function () {
198+
rl0130.with({ monthCode: "M04" }, options);
199+
}, "leap-year Tevet rejects 30");
200+
201+
TemporalHelpers.assertPlainDate(
202+
rl0130.with({ monthCode: "M05" }),
203+
5782, 5, "M05", 30, "leap-year Shevat does not reject 30",
204+
"am", 5782);
205+
206+
TemporalHelpers.assertPlainDate(
207+
rl0130.with({ monthCode: "M05L" }),
208+
5782, 6, "M05L", 30, "leap-year Adar I does not reject 30",
209+
"am", 5782);
210+
211+
TemporalHelpers.assertPlainDate(
212+
rl0130.with({ monthCode: "M06" }),
213+
5782, 7, "M06", 29, "leap-year Adar II constrains to 29",
214+
"am", 5782);
215+
assert.throws(RangeError, function () {
216+
rl0130.with({ monthCode: "M06" }, options);
217+
}, "leap-year Adar II rejects 30");
218+
219+
TemporalHelpers.assertPlainDate(
220+
rl0130.with({ monthCode: "M07" }),
221+
5782, 8, "M07", 30, "leap-year Nisan does not reject 30",
222+
"am", 5782);
223+
224+
TemporalHelpers.assertPlainDate(
225+
rl0130.with({ monthCode: "M08" }),
226+
5782, 9, "M08", 29, "leap-year Iyar constrains to 29",
227+
"am", 5782);
228+
assert.throws(RangeError, function () {
229+
rl0130.with({ monthCode: "M08" }, options);
230+
}, "leap-year Iyar rejects 30");
231+
232+
TemporalHelpers.assertPlainDate(
233+
rl0130.with({ monthCode: "M09" }),
234+
5782, 10, "M09", 30, "leap-year Sivan does not reject 30",
235+
"am", 5782);
236+
237+
TemporalHelpers.assertPlainDate(
238+
rl0130.with({ monthCode: "M10" }),
239+
5782, 11, "M10", 29, "leap-year Tammuz constrains to 29",
240+
"am", 5782);
241+
assert.throws(RangeError, function () {
242+
rl0130.with({ monthCode: "M10" }, options);
243+
}, "leap-year Tammuz rejects 30");
244+
245+
TemporalHelpers.assertPlainDate(
246+
rl0130.with({ monthCode: "M11" }),
247+
5782, 12, "M11", 30, "leap-year Av does not reject 30",
248+
"am", 5782);
249+
250+
TemporalHelpers.assertPlainDate(
251+
rl0130.with({ monthCode: "M12" }),
252+
5782, 13, "M12", 29, "leap-year Elul constrains to 29",
253+
"am", 5782);
254+
assert.throws(RangeError, function () {
255+
rl0130.with({ monthCode: "M12" }, options);
256+
}, "leap-year Elul rejects 30");

0 commit comments

Comments
 (0)