Skip to content

Commit ae4cb32

Browse files
committed
Allow different approximations in the observational Islamic calendar
The "islamic" calendar id refers to the observational Islamic calendar and different implementation may use different algorithms to approximate when the moon's crescent can be observed. Change the test data to allow the approximations used in ICU4X in addition to the ones used in ICU4C. Additionally allow implementations to canonicalise the calendar id.
1 parent 57b9f15 commit ae4cb32

File tree

1 file changed

+58
-14
lines changed

1 file changed

+58
-14
lines changed

test/staging/Intl402/Temporal/old/islamic-calendars.js

+58-14
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,27 @@ features: [Temporal]
1212
const tests = [
1313
{
1414
calendar: "islamic",
15-
inLeapYear: false,
16-
daysInYear: 354,
17-
daysInMonth12: 29,
18-
isoYear: 2023,
19-
isoMonth: 7,
20-
isoDay: 18
15+
choices: [
16+
// Approximations of the observational Islamic calendar as computed by ICU4C.
17+
{
18+
inLeapYear: false,
19+
daysInYear: 354,
20+
daysInMonth12: 29,
21+
isoYear: 2023,
22+
isoMonth: 7,
23+
isoDay: 18
24+
},
25+
26+
// Approximations of the observational Islamic calendar as computed by ICU4X.
27+
{
28+
inLeapYear: true,
29+
daysInYear: 355,
30+
daysInMonth12: 30,
31+
isoYear: 2023,
32+
isoMonth: 7,
33+
isoDay: 19
34+
}
35+
],
2136
},
2237
{
2338
calendar: "islamic-umalqura",
@@ -48,12 +63,27 @@ const tests = [
4863
},
4964
{
5065
calendar: "islamic-rgsa",
51-
inLeapYear: false,
52-
daysInYear: 354,
53-
daysInMonth12: 29,
54-
isoYear: 2023,
55-
isoMonth: 7,
56-
isoDay: 18
66+
choices: [
67+
// Approximations of the observational Islamic calendar as computed by ICU4C.
68+
{
69+
inLeapYear: false,
70+
daysInYear: 354,
71+
daysInMonth12: 29,
72+
isoYear: 2023,
73+
isoMonth: 7,
74+
isoDay: 18
75+
},
76+
77+
// Approximations of the observational Islamic calendar as computed by ICU4X.
78+
{
79+
inLeapYear: true,
80+
daysInYear: 355,
81+
daysInMonth12: 30,
82+
isoYear: 2023,
83+
isoMonth: 7,
84+
isoDay: 19
85+
}
86+
],
5787
},
5888
{
5989
calendar: "islamic-tbla",
@@ -67,15 +97,29 @@ const tests = [
6797
];
6898

6999
for (const test of tests) {
70-
const { calendar, inLeapYear, daysInYear, daysInMonth12, isoYear, isoMonth, isoDay } = test;
100+
const { calendar, choices = [test] } = test;
71101
const year = 1445;
72102
const date = Temporal.PlainDate.from({ year, month: 1, day: 1, calendar });
73103
const isoFields = date.getISOFields();
74-
assert.sameValue(date.calendarId, calendar);
104+
if (calendar !== "islamicc") {
105+
assert.sameValue(date.calendarId, calendar);
106+
} else {
107+
// TODO: Steps to canonicalize the calendar identifier are still missing.
108+
// https://github.com/tc39/ecma402/issues/828
109+
}
75110
assert.sameValue(date.year, year);
76111
assert.sameValue(date.month, 1);
77112
assert.sameValue(date.monthCode, "M01");
78113
assert.sameValue(date.day, 1);
114+
115+
// Match the possible choice by comparing the ISO month and day values.
116+
const choice = choices.find(({ isoMonth, isoDay }) => {
117+
return isoFields.isoMonth === isoMonth && isoFields.isoDay === isoDay;
118+
});
119+
assert(choice !== undefined, `No applicable choice found for calendar: ${calendar}`);
120+
121+
const { inLeapYear, daysInYear, daysInMonth12, isoYear, isoMonth, isoDay } = choice;
122+
79123
assert.sameValue(date.inLeapYear, inLeapYear);
80124
assert.sameValue(date.daysInYear, daysInYear);
81125
assert.sameValue(date.monthsInYear, 12);

0 commit comments

Comments
 (0)