Skip to content

Commit 7b28659

Browse files
committed
Intl Era Monthcode: Adapt PlainDate.add/subtract tests to PlainYearMonth
This commit copies all of the PlainDate.since and .until tests that would apply to PlainYearMonth, and adapts them where necessary. (Except for the tests that would be affected by tc39/proposal-temporal#3197, namely leap-months-*.js and leap-year-*.js [the latter except 'leap-year-hebrew.js' which is fine because of the month constraining behaviour].)
1 parent f866b4b commit 7b28659

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+4545
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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: >
7+
Check various basic calculations not involving leap years or constraining
8+
(buddhist calendar)
9+
features: [Temporal, Intl.Era-monthcode]
10+
includes: [temporalHelpers.js]
11+
---*/
12+
13+
const calendar = "buddhist";
14+
15+
const years1 = new Temporal.Duration(1);
16+
const years1n = new Temporal.Duration(-1);
17+
const years4 = new Temporal.Duration(4);
18+
const years4n = new Temporal.Duration(-4);
19+
20+
const date256407 = Temporal.PlainYearMonth.from({ year: 2564, monthCode: "M07", calendar });
21+
22+
TemporalHelpers.assertPlainYearMonth(
23+
date256407.add(years1),
24+
2565, 7, "M07", "add 1y",
25+
"be", 2565, null);
26+
TemporalHelpers.assertPlainYearMonth(
27+
date256407.add(years4),
28+
2568, 7, "M07", "add 4y",
29+
"be", 2568, null);
30+
31+
TemporalHelpers.assertPlainYearMonth(
32+
date256407.add(years1n),
33+
2563, 7, "M07", "subtract 1y",
34+
"be", 2563, null);
35+
TemporalHelpers.assertPlainYearMonth(
36+
date256407.add(years4n),
37+
2560, 7, "M07", "subtract 4y",
38+
"be", 2560, null);
39+
40+
// Months
41+
42+
const months5 = new Temporal.Duration(0, 5);
43+
const months5n = new Temporal.Duration(0, -5);
44+
const months6 = new Temporal.Duration(0, 6);
45+
const months6n = new Temporal.Duration(0, -6);
46+
const years1months2 = new Temporal.Duration(1, 2);
47+
const years1months2n = new Temporal.Duration(-1, -2);
48+
49+
const date255512 = Temporal.PlainYearMonth.from({ year: 2555, monthCode: "M12", calendar });
50+
51+
TemporalHelpers.assertPlainYearMonth(
52+
date256407.add(months5),
53+
2564, 12, "M12", "add 5mo with result in the same year",
54+
"be", 2564, null);
55+
TemporalHelpers.assertPlainYearMonth(
56+
Temporal.PlainYearMonth.from({ year: 2564, monthCode: "M08", calendar }).add(months5),
57+
2565, 1, "M01", "add 5mo with result in the next year",
58+
"be", 2565, null);
59+
TemporalHelpers.assertPlainYearMonth(
60+
Temporal.PlainYearMonth.from({ year: 2562, monthCode: "M10", calendar }).add(months5),
61+
2563, 3, "M03", "add 5mo with result in the next year on day 1 of month",
62+
"be", 2563, null);
63+
TemporalHelpers.assertPlainYearMonth(
64+
Temporal.PlainYearMonth.from({ year: 2564, monthCode: "M10", calendar }).add(months5),
65+
2565, 3, "M03", "add 5mo with result in the next year on day 31 of month",
66+
"be", 2565, null);
67+
68+
TemporalHelpers.assertPlainYearMonth(
69+
date256407.add(years1months2),
70+
2565, 9, "M09", "add 1y 2mo",
71+
"be", 2565, null);
72+
TemporalHelpers.assertPlainYearMonth(
73+
Temporal.PlainYearMonth.from({ year: 2564, monthCode: "M11", calendar }).add(years1months2),
74+
2566, 1, "M01", "add 1y 2mo with result in the next year",
75+
"be", 2566, null);
76+
77+
TemporalHelpers.assertPlainYearMonth(
78+
date256407.add(months5n),
79+
2564, 2, "M02", "subtract 5mo with result in the same year",
80+
"be", 2564, null);
81+
TemporalHelpers.assertPlainYearMonth(
82+
Temporal.PlainYearMonth.from({ year: 2564, monthCode: "M01", calendar }).add(months5n),
83+
2563, 8, "M08", "subtract 5mo with result in the previous year",
84+
"be", 2563, null);
85+
TemporalHelpers.assertPlainYearMonth(
86+
Temporal.PlainYearMonth.from({ year: 2562, monthCode: "M02", calendar }).add(months5n),
87+
2561, 9, "M09", "subtract 5mo with result in the previous year on day 1 of month",
88+
"be", 2561, null);
89+
TemporalHelpers.assertPlainYearMonth(
90+
Temporal.PlainYearMonth.from({ year: 2564, monthCode: "M03", calendar }).add(months5n),
91+
2563, 10, "M10", "subtract 5mo with result in the previous year on day 31 of month",
92+
"be", 2563, null);
93+
94+
TemporalHelpers.assertPlainYearMonth(
95+
date256407.add(years1months2n),
96+
2563, 5, "M05", "subtract 1y 2mo",
97+
"be", 2563, null);
98+
TemporalHelpers.assertPlainYearMonth(
99+
Temporal.PlainYearMonth.from({ year: 2564, monthCode: "M02", calendar }).add(years1months2n),
100+
2562, 12, "M12", "subtract 1y 2mo with result in the previous year",
101+
"be", 2562, null);
102+
103+
TemporalHelpers.assertPlainYearMonth(
104+
date255512.add(months6),
105+
2556, 6, "M06", "add 6mo",
106+
"be", 2556, null);
107+
const calculatedStart = date255512.add(months6).add(months6n);
108+
TemporalHelpers.assertPlainYearMonth(
109+
calculatedStart,
110+
2555, 12, "M12", "subtract 6mo",
111+
"be", 2555, null);
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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: Basic addition and subtraction in the chinese calendar
7+
features: [Temporal, Intl.Era-monthcode]
8+
includes: [temporalHelpers.js]
9+
---*/
10+
11+
const calendar = "chinese";
12+
const options = { overflow: "reject" };
13+
14+
// Years
15+
16+
const years1 = new Temporal.Duration(1);
17+
const years1n = new Temporal.Duration(-1);
18+
const years5 = new Temporal.Duration(5);
19+
const years5n = new Temporal.Duration(-5);
20+
21+
const date201802 = Temporal.PlainYearMonth.from({ year: 2018, monthCode: "M02", calendar }, options);
22+
23+
TemporalHelpers.assertPlainYearMonth(
24+
date201802.add(years1),
25+
2019, 2, "M02", "Adding 1 year",
26+
undefined, undefined, null);
27+
28+
TemporalHelpers.assertPlainYearMonth(
29+
date201802.add(years5),
30+
2023, 2, "M02", "Adding 5 years",
31+
undefined, undefined, null);
32+
33+
TemporalHelpers.assertPlainYearMonth(
34+
date201802.add(years1n),
35+
2017, 2, "M02", "Subtracting 1 year",
36+
undefined, undefined, null);
37+
38+
TemporalHelpers.assertPlainYearMonth(
39+
date201802.add(years5n),
40+
2013, 2, "M02", "Subtracting 5 years",
41+
undefined, undefined, null);
42+
43+
// Months
44+
45+
const months1 = new Temporal.Duration(0, 1);
46+
const months1n = new Temporal.Duration(0, -1);
47+
const months4 = new Temporal.Duration(0, 4);
48+
const months4n = new Temporal.Duration(0, -4);
49+
const months6 = new Temporal.Duration(0, 6);
50+
const months6n = new Temporal.Duration(0, -6);
51+
52+
const date201901 = Temporal.PlainYearMonth.from({ year: 2019, monthCode: "M01", calendar }, options);
53+
const date201906 = Temporal.PlainYearMonth.from({ year: 2019, monthCode: "M06", calendar }, options);
54+
const date201911 = Temporal.PlainYearMonth.from({ year: 2019, monthCode: "M11", calendar }, options);
55+
const date201912 = Temporal.PlainYearMonth.from({ year: 2019, monthCode: "M12", calendar }, options);
56+
const date200012 = Temporal.PlainYearMonth.from({ year: 2000, monthCode: "M12", calendar }, options);
57+
58+
TemporalHelpers.assertPlainYearMonth(
59+
date201911.add(months1),
60+
2019, 12, "M12", "Adding 1 month, with result in same year",
61+
undefined, undefined, null);
62+
63+
TemporalHelpers.assertPlainYearMonth(
64+
date201912.add(months1),
65+
2020, 1, "M01", "Adding 1 month, with result in next year",
66+
undefined, undefined, null);
67+
68+
TemporalHelpers.assertPlainYearMonth(
69+
date201906.add(months4),
70+
2019, 10, "M10", "Adding 4 months, with result in same year",
71+
undefined, undefined, null);
72+
73+
TemporalHelpers.assertPlainYearMonth(
74+
date201912.add(months4),
75+
2020, 4, "M04", "Adding 4 months, with result in next year",
76+
undefined, undefined, null);
77+
78+
TemporalHelpers.assertPlainYearMonth(
79+
date201911.add(months1n),
80+
2019, 10, "M10", "Subtracting 1 month, with result in same year",
81+
undefined, undefined, null);
82+
83+
TemporalHelpers.assertPlainYearMonth(
84+
date201901.add(months1n),
85+
2018, 12, "M12", "Subtracting 1 month, with result in previous year",
86+
undefined, undefined, null);
87+
88+
TemporalHelpers.assertPlainYearMonth(
89+
date201906.add(months4n),
90+
2019, 2, "M02", "Subtracting 4 months, with result in same year",
91+
undefined, undefined, null);
92+
93+
TemporalHelpers.assertPlainYearMonth(
94+
date201901.add(months4n),
95+
2018, 9, "M09", "Subtracting 4 months, with result in previous year",
96+
undefined, undefined, null);
97+
98+
TemporalHelpers.assertPlainYearMonth(
99+
date200012.add(months6),
100+
2001, 6, "M05", "Adding 6 months, with result in next year (leap year)",
101+
undefined, undefined, null);
102+
103+
TemporalHelpers.assertPlainYearMonth(
104+
date200012.add(months6n),
105+
2000, 6, "M06", "Subtracting 6 months, with result in same year",
106+
undefined, undefined, null);
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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: Basic addition and subtraction in the coptic calendar
7+
features: [Temporal, Intl.Era-monthcode]
8+
includes: [temporalHelpers.js]
9+
---*/
10+
11+
const calendar = "coptic";
12+
const options = { overflow: "reject" };
13+
14+
// Years
15+
16+
const years1 = new Temporal.Duration(1);
17+
const years1n = new Temporal.Duration(-1);
18+
const years5 = new Temporal.Duration(5);
19+
const years5n = new Temporal.Duration(-5);
20+
21+
const date174202 = Temporal.PlainYearMonth.from({ year: 1742, monthCode: "M02", calendar }, options);
22+
23+
TemporalHelpers.assertPlainYearMonth(
24+
date174202.add(years1),
25+
1743, 2, "M02", "Adding 1 year", "am", 1743, null
26+
);
27+
28+
TemporalHelpers.assertPlainYearMonth(
29+
date174202.add(years5),
30+
1747, 2, "M02", "Adding 5 years", "am", 1747, null
31+
);
32+
33+
TemporalHelpers.assertPlainYearMonth(
34+
date174202.add(years1n),
35+
1741, 2, "M02", "Subtracting 1 year", "am", 1741, null
36+
);
37+
38+
TemporalHelpers.assertPlainYearMonth(
39+
date174202.add(years5n),
40+
1737, 2, "M02", "Subtracting 5 years", "am", 1737, null
41+
);
42+
43+
// Months
44+
45+
const months1 = new Temporal.Duration(0, 1);
46+
const months1n = new Temporal.Duration(0, -1);
47+
const months4 = new Temporal.Duration(0, 4);
48+
const months4n = new Temporal.Duration(0, -4);
49+
const months6 = new Temporal.Duration(0, 6);
50+
const months6n = new Temporal.Duration(0, -6);
51+
52+
const date171612 = Temporal.PlainYearMonth.from({ year: 1716, monthCode: "M12", calendar }, options);
53+
const date174301 = Temporal.PlainYearMonth.from({ year: 1743, monthCode: "M01", calendar }, options);
54+
const date174306 = Temporal.PlainYearMonth.from({ year: 1743, monthCode: "M06", calendar }, options);
55+
const date174311 = Temporal.PlainYearMonth.from({ year: 1743, monthCode: "M11", calendar }, options);
56+
const date174213 = Temporal.PlainYearMonth.from({ year: 1742, monthCode: "M13", calendar }, options);
57+
58+
TemporalHelpers.assertPlainYearMonth(
59+
date174311.add(months1),
60+
1743, 12, "M12", "Adding 1 month, with result in same year", "am", 1743, null
61+
);
62+
63+
TemporalHelpers.assertPlainYearMonth(
64+
date174213.add(months1),
65+
1743, 1, "M01", "Adding 1 month, with result in next year", "am", 1743, null
66+
);
67+
68+
TemporalHelpers.assertPlainYearMonth(
69+
date174306.add(months4),
70+
1743, 10, "M10", "Adding 4 months, with result in same year", "am", 1743, null
71+
);
72+
73+
TemporalHelpers.assertPlainYearMonth(
74+
date174213.add(months4),
75+
1743, 4, "M04", "Adding 4 months, with result in next year", "am", 1743, null
76+
);
77+
78+
TemporalHelpers.assertPlainYearMonth(
79+
date174311.add(months1n),
80+
1743, 10, "M10", "Subtracting 1 month, with result in same year", "am", 1743, null
81+
);
82+
83+
TemporalHelpers.assertPlainYearMonth(
84+
date174301.add(months1n),
85+
1742, 13, "M13", "Subtracting 1 month, with result in previous year", "am", 1742, null
86+
);
87+
88+
TemporalHelpers.assertPlainYearMonth(
89+
date174306.add(months4n),
90+
1743, 2, "M02", "Subtracting 4 months, with result in same year", "am", 1743, null
91+
);
92+
93+
TemporalHelpers.assertPlainYearMonth(
94+
date174301.add(months4n),
95+
1742, 10, "M10", "Subtracting 4 months, with result in previous year", "am", 1742, null
96+
);
97+
98+
TemporalHelpers.assertPlainYearMonth(
99+
date171612.add(months6),
100+
1717, 5, "M05", "Adding 6 months, with result in next year", "am", 1717, null
101+
);
102+
const calculatedStart = date171612.add(months6).add(months6n);
103+
TemporalHelpers.assertPlainYearMonth(
104+
calculatedStart,
105+
1716, 12, "M12", "Subtracting 6 months, with result in previous year", "am", 1716, null
106+
);

0 commit comments

Comments
 (0)