|
3 | 3 |
|
4 | 4 | /*--- |
5 | 5 | esid: sec-temporal-intl |
6 | | -description: Islamic calendars (note there are 5 variants) |
| 6 | +description: Islamic calendar "islamic-rgsa". |
7 | 7 | features: [Temporal] |
8 | 8 | ---*/ |
9 | 9 |
|
| 10 | +const calendar = "islamic-rgsa"; |
| 11 | + |
10 | 12 | // Test data obtained from ICU |
11 | 13 |
|
12 | | -const tests = [ |
| 14 | +const choices = [ |
| 15 | + // Approximations of the observational Islamic calendar as computed by ICU4C. |
13 | 16 | { |
14 | | - calendar: "islamic", |
15 | | - choices: [ |
16 | | - // Approximations of the observational Islamic calendar as computed by ICU4C. |
17 | | - { |
18 | | - inLeapYear: false, |
19 | | - daysInYear: 354, |
20 | | - daysInMonth12: 29, |
21 | | - isoDate: "2023-07-18", |
22 | | - }, |
23 | | - |
24 | | - // Approximations of the observational Islamic calendar as computed by ICU4X. |
25 | | - { |
26 | | - inLeapYear: true, |
27 | | - daysInYear: 355, |
28 | | - daysInMonth12: 30, |
29 | | - isoDate: "2023-07-19", |
30 | | - } |
31 | | - ], |
32 | | - }, |
33 | | - { |
34 | | - calendar: "islamic-umalqura", |
35 | 17 | inLeapYear: false, |
36 | 18 | daysInYear: 354, |
37 | | - daysInMonth12: 30, |
38 | | - isoDate: "2023-07-19", |
39 | | - }, |
40 | | - { |
41 | | - calendar: "islamic-civil", |
42 | | - inLeapYear: true, |
43 | | - daysInYear: 355, |
44 | | - daysInMonth12: 30, |
45 | | - isoDate: "2023-07-19", |
| 19 | + daysInMonth12: 29, |
| 20 | + isoDate: "2023-07-18", |
46 | 21 | }, |
47 | | - { |
48 | | - calendar: "islamic-rgsa", |
49 | | - choices: [ |
50 | | - // Approximations of the observational Islamic calendar as computed by ICU4C. |
51 | | - { |
52 | | - inLeapYear: false, |
53 | | - daysInYear: 354, |
54 | | - daysInMonth12: 29, |
55 | | - isoDate: "2023-07-18", |
56 | | - }, |
57 | 22 |
|
58 | | - // Approximations of the observational Islamic calendar as computed by ICU4X. |
59 | | - { |
60 | | - inLeapYear: true, |
61 | | - daysInYear: 355, |
62 | | - daysInMonth12: 30, |
63 | | - isoDate: "2023-07-19", |
64 | | - } |
65 | | - ], |
66 | | - }, |
| 23 | + // Approximations of the observational Islamic calendar as computed by ICU4X. |
67 | 24 | { |
68 | | - calendar: "islamic-tbla", |
69 | 25 | inLeapYear: true, |
70 | 26 | daysInYear: 355, |
71 | 27 | daysInMonth12: 30, |
72 | | - isoDate: "2023-07-18", |
| 28 | + isoDate: "2023-07-19", |
73 | 29 | } |
74 | 30 | ]; |
75 | 31 |
|
76 | | -for (const test of tests) { |
77 | | - const { calendar, choices = [test] } = test; |
78 | | - const year = 1445; |
79 | | - const date = Temporal.PlainDate.from({ year, month: 1, day: 1, calendar }); |
80 | | - assert.sameValue(date.calendarId, calendar); |
81 | | - assert.sameValue(date.year, year); |
82 | | - assert.sameValue(date.month, 1); |
83 | | - assert.sameValue(date.monthCode, "M01"); |
84 | | - assert.sameValue(date.day, 1); |
85 | | - |
86 | | - // Match the possible choice by comparing the ISO date value. |
87 | | - const choice = choices.find(({ isoDate }) => { |
88 | | - return date.toString().startsWith(isoDate); |
89 | | - }); |
90 | | - assert(choice !== undefined, `No applicable choice found for calendar: ${calendar}`); |
91 | | - |
92 | | - const { inLeapYear, daysInYear, daysInMonth12, isoDate } = choice; |
93 | | - |
94 | | - assert.sameValue(date.inLeapYear, inLeapYear); |
95 | | - assert.sameValue(date.daysInYear, daysInYear); |
96 | | - assert.sameValue(date.monthsInYear, 12); |
97 | | - assert.sameValue(date.dayOfYear, 1); |
98 | | - const startOfNextYear = date.with({ year: year + 1 }); |
99 | | - const lastDayOfThisYear = startOfNextYear.subtract({ days: 1 }); |
100 | | - assert.sameValue(lastDayOfThisYear.dayOfYear, daysInYear); |
101 | | - const dateMonth12 = date.with({ month: 12 }); |
102 | | - assert.sameValue(dateMonth12.daysInMonth, daysInMonth12); |
103 | | - assert.sameValue(date.toString(), `${isoDate}[u-ca=${calendar}]`, "ISO reference date"); |
104 | | -} |
| 32 | +const year = 1445; |
| 33 | +const date = Temporal.PlainDate.from({ year, month: 1, day: 1, calendar }); |
| 34 | +assert.sameValue(date.calendarId, calendar); |
| 35 | +assert.sameValue(date.year, year); |
| 36 | +assert.sameValue(date.month, 1); |
| 37 | +assert.sameValue(date.monthCode, "M01"); |
| 38 | +assert.sameValue(date.day, 1); |
| 39 | + |
| 40 | +// Match the possible choice by comparing the ISO date value. |
| 41 | +const choice = choices.find(({ isoDate }) => { |
| 42 | + return date.toString().startsWith(isoDate); |
| 43 | +}); |
| 44 | +assert(choice !== undefined, `No applicable choice found for calendar: ${calendar}`); |
| 45 | + |
| 46 | +const { inLeapYear, daysInYear, daysInMonth12, isoDate } = choice; |
| 47 | + |
| 48 | +assert.sameValue(date.inLeapYear, inLeapYear); |
| 49 | +assert.sameValue(date.daysInYear, daysInYear); |
| 50 | +assert.sameValue(date.monthsInYear, 12); |
| 51 | +assert.sameValue(date.dayOfYear, 1); |
| 52 | + |
| 53 | +const startOfNextYear = date.with({ year: year + 1 }); |
| 54 | +const lastDayOfThisYear = startOfNextYear.subtract({ days: 1 }); |
| 55 | +assert.sameValue(lastDayOfThisYear.dayOfYear, daysInYear); |
| 56 | + |
| 57 | +const dateMonth12 = date.with({ month: 12 }); |
| 58 | +assert.sameValue(dateMonth12.daysInMonth, daysInMonth12); |
| 59 | +assert.sameValue(date.toString(), `${isoDate}[u-ca=${calendar}]`, "ISO reference date"); |
0 commit comments