Skip to content

Commit

Permalink
Allow different approximations in the observational Islamic calendar
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
anba committed May 30, 2024
1 parent 57b9f15 commit ae4cb32
Showing 1 changed file with 58 additions and 14 deletions.
72 changes: 58 additions & 14 deletions test/staging/Intl402/Temporal/old/islamic-calendars.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,27 @@ features: [Temporal]
const tests = [
{
calendar: "islamic",
inLeapYear: false,
daysInYear: 354,
daysInMonth12: 29,
isoYear: 2023,
isoMonth: 7,
isoDay: 18
choices: [
// Approximations of the observational Islamic calendar as computed by ICU4C.
{
inLeapYear: false,
daysInYear: 354,
daysInMonth12: 29,
isoYear: 2023,
isoMonth: 7,
isoDay: 18
},

// Approximations of the observational Islamic calendar as computed by ICU4X.
{
inLeapYear: true,
daysInYear: 355,
daysInMonth12: 30,
isoYear: 2023,
isoMonth: 7,
isoDay: 19
}
],
},
{
calendar: "islamic-umalqura",
Expand Down Expand Up @@ -48,12 +63,27 @@ const tests = [
},
{
calendar: "islamic-rgsa",
inLeapYear: false,
daysInYear: 354,
daysInMonth12: 29,
isoYear: 2023,
isoMonth: 7,
isoDay: 18
choices: [
// Approximations of the observational Islamic calendar as computed by ICU4C.
{
inLeapYear: false,
daysInYear: 354,
daysInMonth12: 29,
isoYear: 2023,
isoMonth: 7,
isoDay: 18
},

// Approximations of the observational Islamic calendar as computed by ICU4X.
{
inLeapYear: true,
daysInYear: 355,
daysInMonth12: 30,
isoYear: 2023,
isoMonth: 7,
isoDay: 19
}
],
},
{
calendar: "islamic-tbla",
Expand All @@ -67,15 +97,29 @@ const tests = [
];

for (const test of tests) {
const { calendar, inLeapYear, daysInYear, daysInMonth12, isoYear, isoMonth, isoDay } = test;
const { calendar, choices = [test] } = test;
const year = 1445;
const date = Temporal.PlainDate.from({ year, month: 1, day: 1, calendar });
const isoFields = date.getISOFields();
assert.sameValue(date.calendarId, calendar);
if (calendar !== "islamicc") {
assert.sameValue(date.calendarId, calendar);
} else {
// TODO: Steps to canonicalize the calendar identifier are still missing.
// https://github.com/tc39/ecma402/issues/828
}
assert.sameValue(date.year, year);
assert.sameValue(date.month, 1);
assert.sameValue(date.monthCode, "M01");
assert.sameValue(date.day, 1);

// Match the possible choice by comparing the ISO month and day values.
const choice = choices.find(({ isoMonth, isoDay }) => {
return isoFields.isoMonth === isoMonth && isoFields.isoDay === isoDay;
});
assert(choice !== undefined, `No applicable choice found for calendar: ${calendar}`);

const { inLeapYear, daysInYear, daysInMonth12, isoYear, isoMonth, isoDay } = choice;

assert.sameValue(date.inLeapYear, inLeapYear);
assert.sameValue(date.daysInYear, daysInYear);
assert.sameValue(date.monthsInYear, 12);
Expand Down

0 comments on commit ae4cb32

Please sign in to comment.