Skip to content

Commit 6a7f6f4

Browse files
jessealamaptomato
andcommitted
Intl Era Monthcode: Era boundary tests for japanese calendar
Co-Authored-By: Philip Chimento <[email protected]>
1 parent ca40d34 commit 6a7f6f4

File tree

6 files changed

+486
-0
lines changed

6 files changed

+486
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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: >
7+
Adding years works correctly across era boundaries in calendars with eras
8+
includes: [temporalHelpers.js]
9+
features: [Temporal, Intl.Era-monthcode]
10+
---*/
11+
12+
// Reiwa era started on May 1, 2019 (Reiwa 1 = 2019)
13+
// Heisei era: 1989-2019 (Heisei 31 ended April 30, 2019)
14+
15+
const duration1 = new Temporal.Duration(1);
16+
const duration1n = new Temporal.Duration(-1);
17+
const calendar = "japanese";
18+
const options = { overflow: "reject" };
19+
20+
const date1 = Temporal.PlainDate.from({ era: "heisei", eraYear: 30, monthCode: "M03", day: 15, calendar }, options);
21+
TemporalHelpers.assertPlainDate(
22+
date1.add(duration1),
23+
2019, 3, "M03", 15, "Adding 1 year to Heisei 30 March (before May 1) lands in Heisei 31 March",
24+
"heisei", 31
25+
);
26+
27+
const date2 = Temporal.PlainDate.from({ era: "heisei", eraYear: 31, monthCode: "M04", day: 15, calendar }, options);
28+
TemporalHelpers.assertPlainDate(
29+
date2.add(duration1),
30+
2020, 4, "M04", 15, "Adding 1 year to Heisei 31 April (before May 1) lands in Reiwa 2 April",
31+
"reiwa", 2
32+
);
33+
34+
const date3 = Temporal.PlainDate.from({ era: "heisei", eraYear: 30, monthCode: "M06", day: 12, calendar }, options);
35+
TemporalHelpers.assertPlainDate(
36+
date3.add(duration1),
37+
2019, 6, "M06", 12, "Adding 1 year to Heisei 30 June (after May 1) lands in Reiwa 1 June",
38+
"reiwa", 1
39+
);
40+
41+
const date4 = Temporal.PlainDate.from({ era: "reiwa", eraYear: 1, monthCode: "M06", day: 10, calendar }, options);
42+
TemporalHelpers.assertPlainDate(
43+
date4.add(duration1),
44+
2020, 6, "M06", 10, "Adding 1 year to Reiwa 1 June lands in Reiwa 2 June",
45+
"reiwa", 2
46+
);
47+
48+
const date5 = Temporal.PlainDate.from({ era: "heisei", eraYear: 28, monthCode: "M07", day: 1, calendar }, options);
49+
TemporalHelpers.assertPlainDate(
50+
date5.add(new Temporal.Duration(3)),
51+
2019, 7, "M07", 1, "Multiple years across era boundary: Adding 3 years to Heisei 28 July lands in Reiwa 1 July",
52+
"reiwa", 1
53+
);
54+
55+
const date6 = Temporal.PlainDate.from({ era: "reiwa", eraYear: 2, monthCode: "M06", day: 15, calendar }, options);
56+
TemporalHelpers.assertPlainDate(
57+
date6.add(duration1n),
58+
2019, 6, "M06", 15, "Subtracting 1 year from Reiwa 2 June lands in Reiwa 1 June",
59+
"reiwa", 1
60+
);
61+
62+
const date7 = Temporal.PlainDate.from({ era: "reiwa", eraYear: 2, monthCode: "M03", day: 15, calendar }, options);
63+
TemporalHelpers.assertPlainDate(
64+
date7.add(duration1n),
65+
2019, 3, "M03", 15, "Subtracting 1 year from Reiwa 2 March lands in Heisei 31 March",
66+
"heisei", 31
67+
);
68+
69+
const date8 = Temporal.PlainDate.from({ era: "reiwa", eraYear: 1, monthCode: "M07", day: 10, calendar }, options);
70+
TemporalHelpers.assertPlainDate(
71+
date8.add(duration1n),
72+
2018, 7, "M07", 10, "Subtracting 1 year from Reiwa 1 July lands in Heisei 30 July",
73+
"heisei", 30
74+
);
75+
76+
const date9 = Temporal.PlainDate.from({ era: "reiwa", eraYear: 4, monthCode: "M02", day: 1, calendar }, options);
77+
TemporalHelpers.assertPlainDate(
78+
date9.add(new Temporal.Duration(-5)),
79+
2017, 2, "M02", 1, "Subtracting 5 years from Reiwa 4 February lands in Heisei 29 February",
80+
"heisei", 29
81+
);
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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: >
7+
Adding years works correctly across era boundaries in calendars with eras
8+
includes: [temporalHelpers.js]
9+
features: [Temporal, Intl.Era-monthcode]
10+
---*/
11+
12+
// Reiwa era started on May 1, 2019 (Reiwa 1 = 2019)
13+
// Heisei era: 1989-2019 (Heisei 31 ended April 30, 2019)
14+
15+
const duration1 = new Temporal.Duration(-1);
16+
const duration1n = new Temporal.Duration(1);
17+
const calendar = "japanese";
18+
const options = { overflow: "reject" };
19+
20+
const date1 = Temporal.PlainDate.from({ era: "heisei", eraYear: 30, monthCode: "M03", day: 15, calendar }, options);
21+
TemporalHelpers.assertPlainDate(
22+
date1.subtract(duration1),
23+
2019, 3, "M03", 15, "Adding 1 year to Heisei 30 March (before May 1) lands in Heisei 31 March",
24+
"heisei", 31
25+
);
26+
27+
const date2 = Temporal.PlainDate.from({ era: "heisei", eraYear: 31, monthCode: "M04", day: 15, calendar }, options);
28+
TemporalHelpers.assertPlainDate(
29+
date2.subtract(duration1),
30+
2020, 4, "M04", 15, "Adding 1 year to Heisei 31 April (before May 1) lands in Reiwa 2 April",
31+
"reiwa", 2
32+
);
33+
34+
const date3 = Temporal.PlainDate.from({ era: "heisei", eraYear: 30, monthCode: "M06", day: 12, calendar }, options);
35+
TemporalHelpers.assertPlainDate(
36+
date3.subtract(duration1),
37+
2019, 6, "M06", 12, "Adding 1 year to Heisei 30 June (after May 1) lands in Reiwa 1 June",
38+
"reiwa", 1
39+
);
40+
41+
const date4 = Temporal.PlainDate.from({ era: "reiwa", eraYear: 1, monthCode: "M06", day: 10, calendar }, options);
42+
TemporalHelpers.assertPlainDate(
43+
date4.subtract(duration1),
44+
2020, 6, "M06", 10, "Adding 1 year to Reiwa 1 June lands in Reiwa 2 June",
45+
"reiwa", 2
46+
);
47+
48+
const date5 = Temporal.PlainDate.from({ era: "heisei", eraYear: 28, monthCode: "M07", day: 1, calendar }, options);
49+
TemporalHelpers.assertPlainDate(
50+
date5.subtract(new Temporal.Duration(-3)),
51+
2019, 7, "M07", 1, "Multiple years across era boundary: Adding 3 years to Heisei 28 July lands in Reiwa 1 July",
52+
"reiwa", 1
53+
);
54+
55+
const date6 = Temporal.PlainDate.from({ era: "reiwa", eraYear: 2, monthCode: "M06", day: 15, calendar }, options);
56+
TemporalHelpers.assertPlainDate(
57+
date6.subtract(duration1n),
58+
2019, 6, "M06", 15, "Subtracting 1 year from Reiwa 2 June lands in Reiwa 1 June",
59+
"reiwa", 1
60+
);
61+
62+
const date7 = Temporal.PlainDate.from({ era: "reiwa", eraYear: 2, monthCode: "M03", day: 15, calendar }, options);
63+
TemporalHelpers.assertPlainDate(
64+
date7.subtract(duration1n),
65+
2019, 3, "M03", 15, "Subtracting 1 year from Reiwa 2 March lands in Heisei 31 March",
66+
"heisei", 31
67+
);
68+
69+
const date8 = Temporal.PlainDate.from({ era: "reiwa", eraYear: 1, monthCode: "M07", day: 10, calendar }, options);
70+
TemporalHelpers.assertPlainDate(
71+
date8.subtract(duration1n),
72+
2018, 7, "M07", 10, "Subtracting 1 year from Reiwa 1 July lands in Heisei 30 July",
73+
"heisei", 30
74+
);
75+
76+
const date9 = Temporal.PlainDate.from({ era: "reiwa", eraYear: 4, monthCode: "M02", day: 1, calendar }, options);
77+
TemporalHelpers.assertPlainDate(
78+
date9.subtract(new Temporal.Duration(5)),
79+
2017, 2, "M02", 1, "Subtracting 5 years from Reiwa 4 February lands in Heisei 29 February",
80+
"heisei", 29
81+
);
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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: >
7+
Adding years works correctly across era boundaries in calendars with eras
8+
includes: [temporalHelpers.js]
9+
features: [Temporal, Intl.Era-monthcode]
10+
---*/
11+
12+
// Reiwa era started on May 1, 2019 (Reiwa 1 = 2019)
13+
// Heisei era: 1989-2019 (Heisei 31 ended April 30, 2019)
14+
15+
const duration1 = new Temporal.Duration(1);
16+
const duration1n = new Temporal.Duration(-1);
17+
const calendar = "japanese";
18+
const options = { overflow: "reject" };
19+
20+
const date1 = Temporal.PlainDateTime.from({ era: "heisei", eraYear: 30, monthCode: "M03", day: 15, hour: 12, minute: 34, calendar }, options);
21+
TemporalHelpers.assertPlainDateTime(
22+
date1.add(duration1),
23+
2019, 3, "M03", 15, 12, 34, 0, 0, 0, 0, "Adding 1 year to Heisei 30 March (before May 1) lands in Heisei 31 March",
24+
"heisei", 31
25+
);
26+
27+
const date2 = Temporal.PlainDateTime.from({ era: "heisei", eraYear: 31, monthCode: "M04", day: 15, hour: 12, minute: 34, calendar }, options);
28+
TemporalHelpers.assertPlainDateTime(
29+
date2.add(duration1),
30+
2020, 4, "M04", 15, 12, 34, 0, 0, 0, 0, "Adding 1 year to Heisei 31 April (before May 1) lands in Reiwa 2 April",
31+
"reiwa", 2
32+
);
33+
34+
const date3 = Temporal.PlainDateTime.from({ era: "heisei", eraYear: 30, monthCode: "M06", day: 12, hour: 12, minute: 34, calendar }, options);
35+
TemporalHelpers.assertPlainDateTime(
36+
date3.add(duration1),
37+
2019, 6, "M06", 12, 12, 34, 0, 0, 0, 0, "Adding 1 year to Heisei 30 June (after May 1) lands in Reiwa 1 June",
38+
"reiwa", 1
39+
);
40+
41+
const date4 = Temporal.PlainDateTime.from({ era: "reiwa", eraYear: 1, monthCode: "M06", day: 10, hour: 12, minute: 34, calendar }, options);
42+
TemporalHelpers.assertPlainDateTime(
43+
date4.add(duration1),
44+
2020, 6, "M06", 10, 12, 34, 0, 0, 0, 0, "Adding 1 year to Reiwa 1 June lands in Reiwa 2 June",
45+
"reiwa", 2
46+
);
47+
48+
const date5 = Temporal.PlainDateTime.from({ era: "heisei", eraYear: 28, monthCode: "M07", day: 1, hour: 12, minute: 34, calendar }, options);
49+
TemporalHelpers.assertPlainDateTime(
50+
date5.add(new Temporal.Duration(3)),
51+
2019, 7, "M07", 1, 12, 34, 0, 0, 0, 0, "Multiple years across era boundary: Adding 3 years to Heisei 28 July lands in Reiwa 1 July",
52+
"reiwa", 1
53+
);
54+
55+
const date6 = Temporal.PlainDateTime.from({ era: "reiwa", eraYear: 2, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options);
56+
TemporalHelpers.assertPlainDateTime(
57+
date6.add(duration1n),
58+
2019, 6, "M06", 15, 12, 34, 0, 0, 0, 0, "Subtracting 1 year from Reiwa 2 June lands in Reiwa 1 June",
59+
"reiwa", 1
60+
);
61+
62+
const date7 = Temporal.PlainDateTime.from({ era: "reiwa", eraYear: 2, monthCode: "M03", day: 15, hour: 12, minute: 34, calendar }, options);
63+
TemporalHelpers.assertPlainDateTime(
64+
date7.add(duration1n),
65+
2019, 3, "M03", 15, 12, 34, 0, 0, 0, 0, "Subtracting 1 year from Reiwa 2 March lands in Heisei 31 March",
66+
"heisei", 31
67+
);
68+
69+
const date8 = Temporal.PlainDateTime.from({ era: "reiwa", eraYear: 1, monthCode: "M07", day: 10, hour: 12, minute: 34, calendar }, options);
70+
TemporalHelpers.assertPlainDateTime(
71+
date8.add(duration1n),
72+
2018, 7, "M07", 10, 12, 34, 0, 0, 0, 0, "Subtracting 1 year from Reiwa 1 July lands in Heisei 30 July",
73+
"heisei", 30
74+
);
75+
76+
const date9 = Temporal.PlainDateTime.from({ era: "reiwa", eraYear: 4, monthCode: "M02", day: 1, hour: 12, minute: 34, calendar }, options);
77+
TemporalHelpers.assertPlainDateTime(
78+
date9.add(new Temporal.Duration(-5)),
79+
2017, 2, "M02", 1, 12, 34, 0, 0, 0, 0, "Subtracting 5 years from Reiwa 4 February lands in Heisei 29 February",
80+
"heisei", 29
81+
);
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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: >
7+
Adding years works correctly across era boundaries in calendars with eras
8+
includes: [temporalHelpers.js]
9+
features: [Temporal, Intl.Era-monthcode]
10+
---*/
11+
12+
// Reiwa era started on May 1, 2019 (Reiwa 1 = 2019)
13+
// Heisei era: 1989-2019 (Heisei 31 ended April 30, 2019)
14+
15+
const duration1 = new Temporal.Duration(-1);
16+
const duration1n = new Temporal.Duration(1);
17+
const calendar = "japanese";
18+
const options = { overflow: "reject" };
19+
20+
const date1 = Temporal.PlainDateTime.from({ era: "heisei", eraYear: 30, monthCode: "M03", day: 15, hour: 12, minute: 34, calendar }, options);
21+
TemporalHelpers.assertPlainDateTime(
22+
date1.subtract(duration1),
23+
2019, 3, "M03", 15, 12, 34, 0, 0, 0, 0, "Adding 1 year to Heisei 30 March (before May 1) lands in Heisei 31 March",
24+
"heisei", 31
25+
);
26+
27+
const date2 = Temporal.PlainDateTime.from({ era: "heisei", eraYear: 31, monthCode: "M04", day: 15, hour: 12, minute: 34, calendar }, options);
28+
TemporalHelpers.assertPlainDateTime(
29+
date2.subtract(duration1),
30+
2020, 4, "M04", 15, 12, 34, 0, 0, 0, 0, "Adding 1 year to Heisei 31 April (before May 1) lands in Reiwa 2 April",
31+
"reiwa", 2
32+
);
33+
34+
const date3 = Temporal.PlainDateTime.from({ era: "heisei", eraYear: 30, monthCode: "M06", day: 12, hour: 12, minute: 34, calendar }, options);
35+
TemporalHelpers.assertPlainDateTime(
36+
date3.subtract(duration1),
37+
2019, 6, "M06", 12, 12, 34, 0, 0, 0, 0, "Adding 1 year to Heisei 30 June (after May 1) lands in Reiwa 1 June",
38+
"reiwa", 1
39+
);
40+
41+
const date4 = Temporal.PlainDateTime.from({ era: "reiwa", eraYear: 1, monthCode: "M06", day: 10, hour: 12, minute: 34, calendar }, options);
42+
TemporalHelpers.assertPlainDateTime(
43+
date4.subtract(duration1),
44+
2020, 6, "M06", 10, 12, 34, 0, 0, 0, 0, "Adding 1 year to Reiwa 1 June lands in Reiwa 2 June",
45+
"reiwa", 2
46+
);
47+
48+
const date5 = Temporal.PlainDateTime.from({ era: "heisei", eraYear: 28, monthCode: "M07", day: 1, hour: 12, minute: 34, calendar }, options);
49+
TemporalHelpers.assertPlainDateTime(
50+
date5.subtract(new Temporal.Duration(-3)),
51+
2019, 7, "M07", 1, 12, 34, 0, 0, 0, 0, "Multiple years across era boundary: Adding 3 years to Heisei 28 July lands in Reiwa 1 July",
52+
"reiwa", 1
53+
);
54+
55+
const date6 = Temporal.PlainDateTime.from({ era: "reiwa", eraYear: 2, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options);
56+
TemporalHelpers.assertPlainDateTime(
57+
date6.subtract(duration1n),
58+
2019, 6, "M06", 15, 12, 34, 0, 0, 0, 0, "Subtracting 1 year from Reiwa 2 June lands in Reiwa 1 June",
59+
"reiwa", 1
60+
);
61+
62+
const date7 = Temporal.PlainDateTime.from({ era: "reiwa", eraYear: 2, monthCode: "M03", day: 15, hour: 12, minute: 34, calendar }, options);
63+
TemporalHelpers.assertPlainDateTime(
64+
date7.subtract(duration1n),
65+
2019, 3, "M03", 15, 12, 34, 0, 0, 0, 0, "Subtracting 1 year from Reiwa 2 March lands in Heisei 31 March",
66+
"heisei", 31
67+
);
68+
69+
const date8 = Temporal.PlainDateTime.from({ era: "reiwa", eraYear: 1, monthCode: "M07", day: 10, hour: 12, minute: 34, calendar }, options);
70+
TemporalHelpers.assertPlainDateTime(
71+
date8.subtract(duration1n),
72+
2018, 7, "M07", 10, 12, 34, 0, 0, 0, 0, "Subtracting 1 year from Reiwa 1 July lands in Heisei 30 July",
73+
"heisei", 30
74+
);
75+
76+
const date9 = Temporal.PlainDateTime.from({ era: "reiwa", eraYear: 4, monthCode: "M02", day: 1, hour: 12, minute: 34, calendar }, options);
77+
TemporalHelpers.assertPlainDateTime(
78+
date9.subtract(new Temporal.Duration(5)),
79+
2017, 2, "M02", 1, 12, 34, 0, 0, 0, 0, "Subtracting 5 years from Reiwa 4 February lands in Heisei 29 February",
80+
"heisei", 29
81+
);

0 commit comments

Comments
 (0)