Skip to content

Commit 26058a0

Browse files
authored
Temporal: Coverage for wrapping at the end of the month (#4695)
Covers Indian, Hijri, and Persian calendars
1 parent a5eaadf commit 26058a0

File tree

49 files changed

+2383
-19
lines changed

Some content is hidden

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

49 files changed

+2383
-19
lines changed

test/built-ins/Temporal/PlainDate/prototype/since/wrapping-at-end-of-month.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
22
// This code is governed by the BSD license found in the LICENSE file.
33

44
/*---

test/intl402/Temporal/PlainDate/prototype/since/wrapping-at-end-of-month-buddhist.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
22
// This code is governed by the BSD license found in the LICENSE file.
33

44
/*---

test/intl402/Temporal/PlainDate/prototype/since/wrapping-at-end-of-month-chinese.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
22
// This code is governed by the BSD license found in the LICENSE file.
33

44
/*---

test/intl402/Temporal/PlainDate/prototype/since/wrapping-at-end-of-month-dangi.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
22
// This code is governed by the BSD license found in the LICENSE file.
33

44
/*---
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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.since
6+
description: Tests balancing of days to months at end of month (indian calendar)
7+
includes: [temporalHelpers.js]
8+
features: [Temporal, Intl.Era-monthcode]
9+
---*/
10+
11+
const calendar = "indian";
12+
13+
// Difference between end of longer month to end of following shorter month
14+
{
15+
const end = Temporal.PlainDate.from({ year: 1945, monthCode: "M07", day: 30, calendar });
16+
for (const largestUnit of ["years", "months"]) {
17+
TemporalHelpers.assertDuration(
18+
Temporal.PlainDate.from({ year: 1945, monthCode: "M06", day: 30, calendar }).since(end, { largestUnit }),
19+
0, -1, 0, 0, 0, 0, 0, 0, 0, 0,
20+
`Bhadra 30th to Asvina 30th is one month (${largestUnit})`
21+
);
22+
TemporalHelpers.assertDuration(
23+
Temporal.PlainDate.from({ year: 1945, monthCode: "M06", day: 31, calendar }).since(end, { largestUnit }),
24+
0, 0, 0, -30, 0, 0, 0, 0, 0, 0,
25+
`Bhadra 31st to Asvina 30th is 30 days, not one month (${largestUnit})`
26+
);
27+
}
28+
}
29+
30+
// Difference between end of longer month to end of not-immediately-following
31+
// shorter month
32+
{
33+
const end = Temporal.PlainDate.from({ year: 1945, monthCode: "M08", day: 30, calendar });
34+
for (const largestUnit of ["years", "months"]) {
35+
TemporalHelpers.assertDuration(
36+
Temporal.PlainDate.from({ year: 1945, monthCode: "M06", day: 30, calendar }).since(end, { largestUnit }),
37+
0, -2, 0, 0, 0, 0, 0, 0, 0, 0,
38+
`Bhadra 30th to Kartika 30th is 2 months (${largestUnit})`
39+
);
40+
TemporalHelpers.assertDuration(
41+
Temporal.PlainDate.from({ year: 1945, monthCode: "M06", day: 31, calendar }).since(end, { largestUnit }),
42+
0, -1, 0, -30, 0, 0, 0, 0, 0, 0,
43+
`Bhadra 31st to Kartika 30th is 1 month 30 days, not 2 months (${largestUnit})`
44+
);
45+
}
46+
}
47+
48+
// Difference between end of longer month in one year to shorter month in
49+
// later year
50+
{
51+
const end = Temporal.PlainDate.from({ year: 1950, monthCode: "M07", day: 30, calendar });
52+
TemporalHelpers.assertDuration(
53+
Temporal.PlainDate.from({ year: 1945, monthCode: "M06", day: 30, calendar }).since(end, { largestUnit: "months" }),
54+
0, -61, 0, 0, 0, 0, 0, 0, 0, 0,
55+
"Bhadra 30th 1945 to Asvina 30th 1950 is 61 months"
56+
);
57+
TemporalHelpers.assertDuration(
58+
Temporal.PlainDate.from({ year: 1945, monthCode: "M06", day: 30, calendar }).since(end, { largestUnit: "years" }),
59+
-5, -1, 0, 0, 0, 0, 0, 0, 0, 0,
60+
"Bhadra 30th 1945 to Asvina 30th 1950 is 5 years, 1 month"
61+
);
62+
TemporalHelpers.assertDuration(
63+
Temporal.PlainDate.from({ year: 1945, monthCode: "M06", day: 31, calendar }).since(end, { largestUnit: "months" }),
64+
0, -60, 0, -30, 0, 0, 0, 0, 0, 0,
65+
"Bhadra 31st 1945 to Asvina 30th 1950 is 60 months, 30 days, not 61 months"
66+
);
67+
TemporalHelpers.assertDuration(
68+
Temporal.PlainDate.from({ year: 1945, monthCode: "M06", day: 31, calendar }).since(end, { largestUnit: "years" }),
69+
-5, 0, 0, -30, 0, 0, 0, 0, 0, 0,
70+
"Bhadra 31st 1945 to Asvina 30th 1950 is 5 years, 30 days"
71+
);
72+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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.since
6+
description: Tests balancing of days to months at end of month (Islamic civil calendar)
7+
includes: [temporalHelpers.js]
8+
features: [Temporal, Intl.Era-monthcode]
9+
---*/
10+
11+
const calendar = "islamic-civil";
12+
13+
// Difference between end of longer month to end of following shorter month
14+
{
15+
const end = Temporal.PlainDate.from({ year: 1400, monthCode: "M02", day: 29, calendar });
16+
for (const largestUnit of ["years", "months"]) {
17+
TemporalHelpers.assertDuration(
18+
Temporal.PlainDate.from({ year: 1400, monthCode: "M01", day: 29, calendar }).since(end, { largestUnit }),
19+
0, -1, 0, 0, 0, 0, 0, 0, 0, 0,
20+
`Muharram 29th to Safar 29th is one month (${largestUnit})`
21+
);
22+
TemporalHelpers.assertDuration(
23+
Temporal.PlainDate.from({ year: 1400, monthCode: "M01", day: 30, calendar }).since(end, { largestUnit }),
24+
0, 0, 0, -29, 0, 0, 0, 0, 0, 0,
25+
`Muharram 30th to Safar 29th is 29 days, not one month (${largestUnit})`
26+
);
27+
}
28+
}
29+
30+
// Difference between end of longer month to end of not-immediately-following
31+
// shorter month
32+
{
33+
const end = Temporal.PlainDate.from({ year: 1400, monthCode: "M04", day: 29, calendar });
34+
for (const largestUnit of ["years", "months"]) {
35+
TemporalHelpers.assertDuration(
36+
Temporal.PlainDate.from({ year: 1400, monthCode: "M01", day: 29, calendar }).since(end, { largestUnit }),
37+
0, -3, 0, 0, 0, 0, 0, 0, 0, 0,
38+
`Muharram 29th to Thani 29th is 3 months (${largestUnit})`
39+
);
40+
TemporalHelpers.assertDuration(
41+
Temporal.PlainDate.from({ year: 1400, monthCode: "M01", day: 30, calendar }).since(end, { largestUnit }),
42+
0, -2, 0, -29, 0, 0, 0, 0, 0, 0,
43+
`Muharram 30th to Thani 29th is 2 months 29 days, not 3 months (${largestUnit})`
44+
);
45+
}
46+
}
47+
48+
// Difference between end of longer month in one year to shorter month in
49+
// later year
50+
{
51+
const end = Temporal.PlainDate.from({ year: 1403, monthCode: "M02", day: 29, calendar });
52+
TemporalHelpers.assertDuration(
53+
Temporal.PlainDate.from({ year: 1400, monthCode: "M11", day: 29, calendar }).since(end, { largestUnit: "months" }),
54+
0, -27, 0, 0, 0, 0, 0, 0, 0, 0,
55+
"Qadah 29th 1400 to Safar 29th 1403 is 27 months"
56+
);
57+
TemporalHelpers.assertDuration(
58+
Temporal.PlainDate.from({ year: 1400, monthCode: "M11", day: 29, calendar }).since(end, { largestUnit: "years" }),
59+
-2, -3, 0, 0, 0, 0, 0, 0, 0, 0,
60+
"Qadah 29th 1400 to Safar 29th 1403 is 2 years, 3 months"
61+
);
62+
TemporalHelpers.assertDuration(
63+
Temporal.PlainDate.from({ year: 1400, monthCode: "M11", day: 30, calendar }).since(end, { largestUnit: "months" }),
64+
0, -26, 0, -29, 0, 0, 0, 0, 0, 0,
65+
"Qadah 30th 1400 to Safar 29th 1403 is 26 months, 29 days, not 27 months"
66+
);
67+
TemporalHelpers.assertDuration(
68+
Temporal.PlainDate.from({ year: 1400, monthCode: "M11", day: 30, calendar }).since(end, { largestUnit: "years" }),
69+
-2, -2, 0, -29, 0, 0, 0, 0, 0, 0,
70+
"Qadah 30th 1400 to Safar 29th 1403 is 2 years, 2 months, 29 days, not 2 years 3 months"
71+
);
72+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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.since
6+
description: Tests balancing of days to months at end of month (Islamic tbla calendar)
7+
includes: [temporalHelpers.js]
8+
features: [Temporal, Intl.Era-monthcode]
9+
---*/
10+
11+
const calendar = "islamic-tbla";
12+
13+
// Difference between end of longer month to end of following shorter month
14+
{
15+
const end = Temporal.PlainDate.from({ year: 1970, monthCode: "M02", day: 29, calendar });
16+
for (const largestUnit of ["years", "months"]) {
17+
TemporalHelpers.assertDuration(
18+
Temporal.PlainDate.from({ year: 1970, monthCode: "M01", day: 29, calendar }).since(end, { largestUnit }),
19+
0, -1, 0, 0, 0, 0, 0, 0, 0, 0,
20+
`Muharram 29th to Safar 29th is one month (${largestUnit})`
21+
);
22+
TemporalHelpers.assertDuration(
23+
Temporal.PlainDate.from({ year: 1970, monthCode: "M01", day: 30, calendar }).since(end, { largestUnit }),
24+
0, 0, 0, -29, 0, 0, 0, 0, 0, 0,
25+
`Muharram 30th to Safar 29th is 29 days, not one month (${largestUnit})`
26+
);
27+
}
28+
}
29+
30+
// Difference between end of longer month to end of not-immediately-following
31+
// shorter month
32+
{
33+
const end = Temporal.PlainDate.from({ year: 1970, monthCode: "M04", day: 29, calendar });
34+
for (const largestUnit of ["years", "months"]) {
35+
TemporalHelpers.assertDuration(
36+
Temporal.PlainDate.from({ year: 1970, monthCode: "M01", day: 29, calendar }).since(end, { largestUnit }),
37+
0, -3, 0, 0, 0, 0, 0, 0, 0, 0,
38+
`Muharram 29th to Thani 29th is 3 months (${largestUnit})`
39+
);
40+
TemporalHelpers.assertDuration(
41+
Temporal.PlainDate.from({ year: 1970, monthCode: "M01", day: 30, calendar }).since(end, { largestUnit }),
42+
0, -2, 0, -29, 0, 0, 0, 0, 0, 0,
43+
`Muharram 30th to Thani 29th is 2 months 29 days, not 3 months (${largestUnit})`
44+
);
45+
}
46+
}
47+
48+
// Difference between end of longer month in one year to shorter month in
49+
// later year
50+
{
51+
const end = Temporal.PlainDate.from({ year: 1973, monthCode: "M02", day: 29, calendar });
52+
TemporalHelpers.assertDuration(
53+
Temporal.PlainDate.from({ year: 1970, monthCode: "M11", day: 29, calendar }).since(end, { largestUnit: "months" }),
54+
0, -27, 0, 0, 0, 0, 0, 0, 0, 0,
55+
"Qadah 29th 1970 to Safar 29th 1973 is 27 months"
56+
);
57+
TemporalHelpers.assertDuration(
58+
Temporal.PlainDate.from({ year: 1970, monthCode: "M11", day: 29, calendar }).since(end, { largestUnit: "years" }),
59+
-2, -3, 0, 0, 0, 0, 0, 0, 0, 0,
60+
"Qadah 29th 1970 to Safar 29th 1973 is 2 years, 3 months"
61+
);
62+
TemporalHelpers.assertDuration(
63+
Temporal.PlainDate.from({ year: 1970, monthCode: "M11", day: 30, calendar }).since(end, { largestUnit: "months" }),
64+
0, -26, 0, -29, 0, 0, 0, 0, 0, 0,
65+
"Qadah 30th 1970 to Safar 29th 1973 is 26 months, 29 days, not 27 months"
66+
);
67+
TemporalHelpers.assertDuration(
68+
Temporal.PlainDate.from({ year: 1970, monthCode: "M11", day: 30, calendar }).since(end, { largestUnit: "years" }),
69+
-2, -2, 0, -29, 0, 0, 0, 0, 0, 0,
70+
"Qadah 30th 1970 to Safar 29th 1973 is 2 years, 2 months, 29 days, not 2 years 3 months"
71+
);
72+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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.since
6+
description: Tests balancing of days to months at end of month (Islamic Umm al-Qura calendar)
7+
includes: [temporalHelpers.js]
8+
features: [Temporal, Intl.Era-monthcode]
9+
---*/
10+
11+
const calendar = "islamic-umalqura";
12+
13+
// Difference between end of longer month to end of following shorter month
14+
{
15+
const end = Temporal.PlainDate.from({ year: 1970, monthCode: "M02", day: 29, calendar });
16+
for (const largestUnit of ["years", "months"]) {
17+
TemporalHelpers.assertDuration(
18+
Temporal.PlainDate.from({ year: 1970, monthCode: "M01", day: 29, calendar }).since(end, { largestUnit }),
19+
0, -1, 0, 0, 0, 0, 0, 0, 0, 0,
20+
`Muharram 29th to Safar 29th is one month (${largestUnit})`
21+
);
22+
TemporalHelpers.assertDuration(
23+
Temporal.PlainDate.from({ year: 1970, monthCode: "M01", day: 30, calendar }).since(end, { largestUnit }),
24+
0, 0, 0, -29, 0, 0, 0, 0, 0, 0,
25+
`Muharram 30th to Safar 29th is 29 days, not one month (${largestUnit})`
26+
);
27+
}
28+
}
29+
30+
// Difference between end of longer month to end of not-immediately-following
31+
// shorter month
32+
{
33+
const end = Temporal.PlainDate.from({ year: 1970, monthCode: "M04", day: 29, calendar });
34+
for (const largestUnit of ["years", "months"]) {
35+
TemporalHelpers.assertDuration(
36+
Temporal.PlainDate.from({ year: 1970, monthCode: "M01", day: 29, calendar }).since(end, { largestUnit }),
37+
0, -3, 0, 0, 0, 0, 0, 0, 0, 0,
38+
`Muharram 29th to Thani 29th is 3 months (${largestUnit})`
39+
);
40+
TemporalHelpers.assertDuration(
41+
Temporal.PlainDate.from({ year: 1970, monthCode: "M01", day: 30, calendar }).since(end, { largestUnit }),
42+
0, -2, 0, -29, 0, 0, 0, 0, 0, 0,
43+
`Muharram 30th to Thani 29th is 2 months 29 days, not 3 months (${largestUnit})`
44+
);
45+
}
46+
}
47+
48+
// Difference between end of longer month in one year to shorter month in
49+
// later year
50+
{
51+
const end = Temporal.PlainDate.from({ year: 1973, monthCode: "M02", day: 29, calendar });
52+
TemporalHelpers.assertDuration(
53+
Temporal.PlainDate.from({ year: 1970, monthCode: "M11", day: 29, calendar }).since(end, { largestUnit: "months" }),
54+
0, -27, 0, 0, 0, 0, 0, 0, 0, 0,
55+
"Qadah 29th 1970 to Safar 29th 1973 is 27 months"
56+
);
57+
TemporalHelpers.assertDuration(
58+
Temporal.PlainDate.from({ year: 1970, monthCode: "M11", day: 29, calendar }).since(end, { largestUnit: "years" }),
59+
-2, -3, 0, 0, 0, 0, 0, 0, 0, 0,
60+
"Qadah 29th 1970 to Safar 29th 1973 is 2 years, 3 months"
61+
);
62+
TemporalHelpers.assertDuration(
63+
Temporal.PlainDate.from({ year: 1970, monthCode: "M11", day: 30, calendar }).since(end, { largestUnit: "months" }),
64+
0, -26, 0, -29, 0, 0, 0, 0, 0, 0,
65+
"Qadah 30th 1970 to Safar 29th 1973 is 26 months, 29 days, not 27 months"
66+
);
67+
TemporalHelpers.assertDuration(
68+
Temporal.PlainDate.from({ year: 1970, monthCode: "M11", day: 30, calendar }).since(end, { largestUnit: "years" }),
69+
-2, -2, 0, -29, 0, 0, 0, 0, 0, 0,
70+
"Qadah 30th 1970 to Safar 29th 1973 is 2 years, 2 months, 29 days, not 2 years 3 months"
71+
);
72+
}

0 commit comments

Comments
 (0)