From ae4cb329ea3f1db07a95a02d4854b11d55950258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Thu, 30 May 2024 10:28:56 +0200 Subject: [PATCH] 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. --- .../Intl402/Temporal/old/islamic-calendars.js | 72 +++++++++++++++---- 1 file changed, 58 insertions(+), 14 deletions(-) diff --git a/test/staging/Intl402/Temporal/old/islamic-calendars.js b/test/staging/Intl402/Temporal/old/islamic-calendars.js index 34ff2755f0d..d028463a582 100644 --- a/test/staging/Intl402/Temporal/old/islamic-calendars.js +++ b/test/staging/Intl402/Temporal/old/islamic-calendars.js @@ -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", @@ -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", @@ -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);