Skip to content

Commit 3928722

Browse files
committed
Intl Era Monthcode: Constrain day to end-of-month, ISO-like calendars
Similar to the previous commit, this adds tests for constraining the day to the end of the month, but using the with() method. For the four ISO8601-like calendars (buddhist, gregory, japanese, roc).
1 parent d35f111 commit 3928722

File tree

12 files changed

+1908
-0
lines changed

12 files changed

+1908
-0
lines changed
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
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 to the end of a month (buddhist calendar)
7+
features: [Temporal]
8+
includes: [temporalHelpers.js]
9+
---*/
10+
11+
const calendar = "buddhist";
12+
const options = { overflow: "reject" };
13+
14+
const common0131 = Temporal.PlainDate.from({ year: 2562, monthCode: "M01", day: 31, calendar }, options);
15+
const leap0131 = Temporal.PlainDate.from({ year: 2559, monthCode: "M01", day: 31, calendar }, options);
16+
17+
// Common year
18+
19+
TemporalHelpers.assertPlainDate(
20+
common0131.with({ monthCode: "M02" }),
21+
2562, 2, "M02", 28, "common-year Feb constrains to 28",
22+
"be", 2562);
23+
assert.throws(RangeError, function () {
24+
common0131.with({ monthCode: "M02" }, options);
25+
}, "common-year Feb rejects with 31");
26+
27+
TemporalHelpers.assertPlainDate(
28+
common0131.with({ monthCode: "M03" }, options),
29+
2562, 3, "M03", 31, "common-year Mar does not reject 31",
30+
"be", 2562);
31+
32+
TemporalHelpers.assertPlainDate(
33+
common0131.with({ monthCode: "M04" }),
34+
2562, 4, "M04", 30, "common-year Apr constrains to 30",
35+
"be", 2562);
36+
assert.throws(RangeError, function () {
37+
common0131.with({ monthCode: "M04" }, options);
38+
}, "common-year Apr rejects with 31");
39+
40+
TemporalHelpers.assertPlainDate(
41+
common0131.with({ monthCode: "M05" }, options),
42+
2562, 5, "M05", 31, "common-year May does not reject 31",
43+
"be", 2562);
44+
45+
TemporalHelpers.assertPlainDate(
46+
common0131.with({ monthCode: "M06" }),
47+
2562, 6, "M06", 30, "common-year Jun constrains to 30",
48+
"be", 2562);
49+
assert.throws(RangeError, function () {
50+
common0131.with({ monthCode: "M06" }, options);
51+
}, "common-year Jun rejects with 31");
52+
53+
TemporalHelpers.assertPlainDate(
54+
common0131.with({ monthCode: "M07" }, options),
55+
2562, 7, "M07", 31, "common-year Jul does not reject 31",
56+
"be", 2562);
57+
58+
TemporalHelpers.assertPlainDate(
59+
common0131.with({ monthCode: "M08" }, options),
60+
2562, 8, "M08", 31, "common-year Aug does not reject 31",
61+
"be", 2562);
62+
63+
TemporalHelpers.assertPlainDate(
64+
common0131.with({ monthCode: "M09" }),
65+
2562, 9, "M09", 30, "common-year Sep constrains to 30",
66+
"be", 2562);
67+
assert.throws(RangeError, function () {
68+
common0131.with({ monthCode: "M09" }, options);
69+
}, "common-year Sep rejects with 31");
70+
71+
TemporalHelpers.assertPlainDate(
72+
common0131.with({ monthCode: "M10" }, options),
73+
2562, 10, "M10", 31, "common-year Oct does not reject 31",
74+
"be", 2562);
75+
76+
TemporalHelpers.assertPlainDate(
77+
common0131.with({ monthCode: "M11" }),
78+
2562, 11, "M11", 30, "common-year Nov constrains to 30",
79+
"be", 2562);
80+
assert.throws(RangeError, function () {
81+
common0131.with({ monthCode: "M11" }, options);
82+
}, "common-year Nov rejects with 31");
83+
84+
TemporalHelpers.assertPlainDate(
85+
common0131.with({ monthCode: "M12" }, options),
86+
2562, 12, "M12", 31, "common-year Dec does not reject 31",
87+
"be", 2562);
88+
89+
// Leap year, forwards
90+
91+
TemporalHelpers.assertPlainDate(
92+
leap0131.with({ monthCode: "M02" }),
93+
2559, 2, "M02", 29, "leap-year Feb constrains to 29",
94+
"be", 2559);
95+
assert.throws(RangeError, function () {
96+
leap0131.with({ monthCode: "M02" }, options);
97+
}, "leap-year Feb rejects with 31");
98+
99+
TemporalHelpers.assertPlainDate(
100+
leap0131.with({ monthCode: "M03" }, options),
101+
2559, 3, "M03", 31, "leap-year Mar does not reject 31",
102+
"be", 2559);
103+
104+
TemporalHelpers.assertPlainDate(
105+
leap0131.with({ monthCode: "M04" }),
106+
2559, 4, "M04", 30, "leap-year Apr constrains to 30",
107+
"be", 2559);
108+
assert.throws(RangeError, function () {
109+
leap0131.with({ monthCode: "M04" }, options);
110+
}, "leap-year Apr rejects with 31");
111+
112+
TemporalHelpers.assertPlainDate(
113+
leap0131.with({ monthCode: "M05" }, options),
114+
2559, 5, "M05", 31, "leap-year May does not reject 31",
115+
"be", 2559);
116+
117+
TemporalHelpers.assertPlainDate(
118+
leap0131.with({ monthCode: "M06" }),
119+
2559, 6, "M06", 30, "leap-year Jun constrains to 30",
120+
"be", 2559);
121+
assert.throws(RangeError, function () {
122+
leap0131.with({ monthCode: "M06" }, options);
123+
}, "leap-year Jun rejects with 31");
124+
125+
TemporalHelpers.assertPlainDate(
126+
leap0131.with({ monthCode: "M07" }, options),
127+
2559, 7, "M07", 31, "leap-year Jul does not reject 31",
128+
"be", 2559);
129+
130+
TemporalHelpers.assertPlainDate(
131+
leap0131.with({ monthCode: "M08" }, options),
132+
2559, 8, "M08", 31, "leap-year Aug does not reject 31",
133+
"be", 2559);
134+
135+
TemporalHelpers.assertPlainDate(
136+
leap0131.with({ monthCode: "M09" }),
137+
2559, 9, "M09", 30, "leap-year Sep constrains to 30",
138+
"be", 2559);
139+
assert.throws(RangeError, function () {
140+
leap0131.with({ monthCode: "M09" }, options);
141+
}, "leap-year Sep rejects with 31");
142+
143+
TemporalHelpers.assertPlainDate(
144+
leap0131.with({ monthCode: "M10" }, options),
145+
2559, 10, "M10", 31, "leap-year Oct does not reject 31",
146+
"be", 2559);
147+
148+
TemporalHelpers.assertPlainDate(
149+
leap0131.with({ monthCode: "M11" }),
150+
2559, 11, "M11", 30, "leap-year Nov constrains to 30",
151+
"be", 2559);
152+
assert.throws(RangeError, function () {
153+
leap0131.with({ monthCode: "M11" }, options);
154+
}, "leap-year Nov rejects with 31");
155+
156+
TemporalHelpers.assertPlainDate(
157+
leap0131.with({ monthCode: "M12" }, options),
158+
2559, 12, "M12", 31, "leap-year Dec does not reject 31",
159+
"be", 2559);
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
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 to the end of a month (gregory calendar)
7+
features: [Temporal]
8+
includes: [temporalHelpers.js]
9+
---*/
10+
11+
const calendar = "gregory";
12+
const options = { overflow: "reject" };
13+
14+
const common0131 = Temporal.PlainDate.from({ year: 2019, monthCode: "M01", day: 31, calendar }, options);
15+
const leap0131 = Temporal.PlainDate.from({ year: 2016, monthCode: "M01", day: 31, calendar }, options);
16+
17+
// Common year
18+
19+
TemporalHelpers.assertPlainDate(
20+
common0131.with({ monthCode: "M02" }),
21+
2019, 2, "M02", 28, "common-year Feb constrains to 28",
22+
"ce", 2019);
23+
assert.throws(RangeError, function () {
24+
common0131.with({ monthCode: "M02" }, options);
25+
}, "common-year Feb rejects with 31");
26+
27+
TemporalHelpers.assertPlainDate(
28+
common0131.with({ monthCode: "M03" }, options),
29+
2019, 3, "M03", 31, "common-year Mar does not reject 31",
30+
"ce", 2019);
31+
32+
TemporalHelpers.assertPlainDate(
33+
common0131.with({ monthCode: "M04" }),
34+
2019, 4, "M04", 30, "common-year Apr constrains to 30",
35+
"ce", 2019);
36+
assert.throws(RangeError, function () {
37+
common0131.with({ monthCode: "M04" }, options);
38+
}, "common-year Apr rejects with 31");
39+
40+
TemporalHelpers.assertPlainDate(
41+
common0131.with({ monthCode: "M05" }, options),
42+
2019, 5, "M05", 31, "common-year May does not reject 31",
43+
"ce", 2019);
44+
45+
TemporalHelpers.assertPlainDate(
46+
common0131.with({ monthCode: "M06" }),
47+
2019, 6, "M06", 30, "common-year Jun constrains to 30",
48+
"ce", 2019);
49+
assert.throws(RangeError, function () {
50+
common0131.with({ monthCode: "M06" }, options);
51+
}, "common-year Jun rejects with 31");
52+
53+
TemporalHelpers.assertPlainDate(
54+
common0131.with({ monthCode: "M07" }, options),
55+
2019, 7, "M07", 31, "common-year Jul does not reject 31",
56+
"ce", 2019);
57+
58+
TemporalHelpers.assertPlainDate(
59+
common0131.with({ monthCode: "M08" }, options),
60+
2019, 8, "M08", 31, "common-year Aug does not reject 31",
61+
"ce", 2019);
62+
63+
TemporalHelpers.assertPlainDate(
64+
common0131.with({ monthCode: "M09" }),
65+
2019, 9, "M09", 30, "common-year Sep constrains to 30",
66+
"ce", 2019);
67+
assert.throws(RangeError, function () {
68+
common0131.with({ monthCode: "M09" }, options);
69+
}, "common-year Sep rejects with 31");
70+
71+
TemporalHelpers.assertPlainDate(
72+
common0131.with({ monthCode: "M10" }, options),
73+
2019, 10, "M10", 31, "common-year Oct does not reject 31",
74+
"ce", 2019);
75+
76+
TemporalHelpers.assertPlainDate(
77+
common0131.with({ monthCode: "M11" }),
78+
2019, 11, "M11", 30, "common-year Nov constrains to 30",
79+
"ce", 2019);
80+
assert.throws(RangeError, function () {
81+
common0131.with({ monthCode: "M11" }, options);
82+
}, "common-year Nov rejects with 31");
83+
84+
TemporalHelpers.assertPlainDate(
85+
common0131.with({ monthCode: "M12" }, options),
86+
2019, 12, "M12", 31, "common-year Dec does not reject 31",
87+
"ce", 2019);
88+
89+
// Leap year, forwards
90+
91+
TemporalHelpers.assertPlainDate(
92+
leap0131.with({ monthCode: "M02" }),
93+
2016, 2, "M02", 29, "leap-year Feb constrains to 29",
94+
"ce", 2016);
95+
assert.throws(RangeError, function () {
96+
leap0131.with({ monthCode: "M02" }, options);
97+
}, "leap-year Feb rejects with 31");
98+
99+
TemporalHelpers.assertPlainDate(
100+
leap0131.with({ monthCode: "M03" }, options),
101+
2016, 3, "M03", 31, "leap-year Mar does not reject 31",
102+
"ce", 2016);
103+
104+
TemporalHelpers.assertPlainDate(
105+
leap0131.with({ monthCode: "M04" }),
106+
2016, 4, "M04", 30, "leap-year Apr constrains to 30",
107+
"ce", 2016);
108+
assert.throws(RangeError, function () {
109+
leap0131.with({ monthCode: "M04" }, options);
110+
}, "leap-year Apr rejects with 31");
111+
112+
TemporalHelpers.assertPlainDate(
113+
leap0131.with({ monthCode: "M05" }, options),
114+
2016, 5, "M05", 31, "leap-year May does not reject 31",
115+
"ce", 2016);
116+
117+
TemporalHelpers.assertPlainDate(
118+
leap0131.with({ monthCode: "M06" }),
119+
2016, 6, "M06", 30, "leap-year Jun constrains to 30",
120+
"ce", 2016);
121+
assert.throws(RangeError, function () {
122+
leap0131.with({ monthCode: "M06" }, options);
123+
}, "leap-year Jun rejects with 31");
124+
125+
TemporalHelpers.assertPlainDate(
126+
leap0131.with({ monthCode: "M07" }, options),
127+
2016, 7, "M07", 31, "leap-year Jul does not reject 31",
128+
"ce", 2016);
129+
130+
TemporalHelpers.assertPlainDate(
131+
leap0131.with({ monthCode: "M08" }, options),
132+
2016, 8, "M08", 31, "leap-year Aug does not reject 31",
133+
"ce", 2016);
134+
135+
TemporalHelpers.assertPlainDate(
136+
leap0131.with({ monthCode: "M09" }),
137+
2016, 9, "M09", 30, "leap-year Sep constrains to 30",
138+
"ce", 2016);
139+
assert.throws(RangeError, function () {
140+
leap0131.with({ monthCode: "M09" }, options);
141+
}, "leap-year Sep rejects with 31");
142+
143+
TemporalHelpers.assertPlainDate(
144+
leap0131.with({ monthCode: "M10" }, options),
145+
2016, 10, "M10", 31, "leap-year Oct does not reject 31",
146+
"ce", 2016);
147+
148+
TemporalHelpers.assertPlainDate(
149+
leap0131.with({ monthCode: "M11" }),
150+
2016, 11, "M11", 30, "leap-year Nov constrains to 30",
151+
"ce", 2016);
152+
assert.throws(RangeError, function () {
153+
leap0131.with({ monthCode: "M11" }, options);
154+
}, "leap-year Nov rejects with 31");
155+
156+
TemporalHelpers.assertPlainDate(
157+
leap0131.with({ monthCode: "M12" }, options),
158+
2016, 12, "M12", 31, "leap-year Dec does not reject 31",
159+
"ce", 2016);

0 commit comments

Comments
 (0)