-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 402 staging tests: Islamic & Persian calendars
Tests the changes in tc39/proposal-temporal#2743
- Loading branch information
1 parent
9c4e0fd
commit 6ee935a
Showing
2 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright (C) 2023 Justin Grant. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal-intl | ||
description: Islamic calendars (note there are 6 variants) | ||
features: [Temporal] | ||
---*/ | ||
|
||
// Test data obtained from ICU | ||
|
||
const tests = [ | ||
{ | ||
calendar: "islamic", | ||
inLeapYear: false, | ||
daysInYear: 354, | ||
daysInMonth12: 29, | ||
isoYear: 2023, | ||
isoMonth: 7, | ||
isoDay: 18 | ||
}, | ||
{ | ||
calendar: "islamic-umalqura", | ||
inLeapYear: false, | ||
daysInYear: 354, | ||
daysInMonth12: 30, | ||
isoYear: 2023, | ||
isoMonth: 7, | ||
isoDay: 19 | ||
}, | ||
{ | ||
calendar: "islamic-civil", | ||
inLeapYear: true, | ||
daysInYear: 355, | ||
daysInMonth12: 30, | ||
isoYear: 2023, | ||
isoMonth: 7, | ||
isoDay: 19 | ||
}, | ||
{ | ||
calendar: "islamicc", // deprecated version of islamic-civil | ||
inLeapYear: true, | ||
daysInYear: 355, | ||
daysInMonth12: 30, | ||
isoYear: 2023, | ||
isoMonth: 7, | ||
isoDay: 19 | ||
}, | ||
{ | ||
calendar: "islamic-rgsa", | ||
inLeapYear: false, | ||
daysInYear: 354, | ||
daysInMonth12: 29, | ||
isoYear: 2023, | ||
isoMonth: 7, | ||
isoDay: 18 | ||
}, | ||
{ | ||
calendar: "islamic-tbla", | ||
inLeapYear: true, | ||
daysInYear: 355, | ||
daysInMonth12: 30, | ||
isoYear: 2023, | ||
isoMonth: 7, | ||
isoDay: 18 | ||
} | ||
]; | ||
|
||
for (const test of tests) { | ||
const { calendar, inLeapYear, daysInYear, daysInMonth12, isoYear, isoMonth, isoDay } = test; | ||
const year = 1445; | ||
const date = Temporal.PlainDate.from({ year, month: 1, day: 1, calendar }); | ||
const isoFields = date.getISOFields(); | ||
assert.sameValue(date.calendarId, calendar); | ||
assert.sameValue(date.year, year); | ||
assert.sameValue(date.month, 1); | ||
assert.sameValue(date.monthCode, "M01"); | ||
assert.sameValue(date.day, 1); | ||
assert.sameValue(date.inLeapYear, inLeapYear); | ||
assert.sameValue(date.daysInYear, daysInYear); | ||
assert.sameValue(date.monthsInYear, 12); | ||
assert.sameValue(date.dayOfYear, 1); | ||
const startOfNextYear = date.with({ year: year + 1 }); | ||
const lastDayOfThisYear = startOfNextYear.subtract({ days: 1 }); | ||
assert.sameValue(lastDayOfThisYear.dayOfYear, daysInYear); | ||
const dateMonth12 = date.with({ month: 12 }); | ||
assert.sameValue(dateMonth12.daysInMonth, daysInMonth12); | ||
assert.sameValue(isoYear, isoFields.isoYear); | ||
assert.sameValue(isoMonth, isoFields.isoMonth); | ||
assert.sameValue(isoDay, isoFields.isoDay); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright (C) 2023 Justin Grant. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal-intl | ||
description: Persian calendar | ||
features: [Temporal] | ||
---*/ | ||
|
||
// Test data obtained from ICU | ||
|
||
const tests = [ | ||
{ | ||
testYear: 1395, | ||
inLeapYear: true, | ||
daysInYear: 366, | ||
daysInMonth12: 30, | ||
isoYear: 2016, | ||
isoMonth: 3, | ||
isoDay: 20 | ||
}, | ||
{ | ||
testYear: 1396, | ||
inLeapYear: false, | ||
daysInYear: 365, | ||
daysInMonth12: 29, | ||
isoYear: 2017, | ||
isoMonth: 3, | ||
isoDay: 21 | ||
}, | ||
{ | ||
testYear: 1397, | ||
inLeapYear: false, | ||
daysInYear: 365, | ||
daysInMonth12: 29, | ||
isoYear: 2018, | ||
isoMonth: 3, | ||
isoDay: 21 | ||
}, | ||
{ | ||
testYear: 1398, | ||
inLeapYear: false, | ||
daysInYear: 365, | ||
daysInMonth12: 29, | ||
isoYear: 2019, | ||
isoMonth: 3, | ||
isoDay: 21 | ||
}, | ||
{ | ||
testYear: 1399, | ||
inLeapYear: true, | ||
daysInYear: 366, | ||
daysInMonth12: 30, | ||
isoYear: 2020, | ||
isoMonth: 3, | ||
isoDay: 20 | ||
}, | ||
{ | ||
testYear: 1400, | ||
inLeapYear: false, | ||
daysInYear: 365, | ||
daysInMonth12: 29, | ||
isoYear: 2021, | ||
isoMonth: 3, | ||
isoDay: 21 | ||
} | ||
]; | ||
|
||
for (const test of tests) { | ||
const { testYear, inLeapYear, daysInYear, daysInMonth12, isoYear, isoMonth, isoDay } = test; | ||
const date = Temporal.PlainDate.from({ year: testYear, month: 1, day: 1, calendar: "persian" }); | ||
const isoFields = date.getISOFields(); | ||
assert.sameValue(date.calendarId, "persian"); | ||
assert.sameValue(date.year, testYear); | ||
assert.sameValue(date.month, 1); | ||
assert.sameValue(date.monthCode, "M01"); | ||
assert.sameValue(date.day, 1); | ||
assert.sameValue(date.inLeapYear, inLeapYear); | ||
assert.sameValue(date.daysInYear, daysInYear); | ||
assert.sameValue(date.monthsInYear, 12); | ||
assert.sameValue(date.dayOfYear, 1); | ||
const startOfNextYear = date.with({ year: testYear + 1 }); | ||
const lastDayOfThisYear = startOfNextYear.subtract({ days: 1 }); | ||
assert.sameValue(lastDayOfThisYear.dayOfYear, daysInYear); | ||
const dateMonth12 = date.with({ month: 12 }); | ||
assert.sameValue(dateMonth12.daysInMonth, daysInMonth12); | ||
assert.sameValue(isoYear, isoFields.isoYear); | ||
assert.sameValue(isoMonth, isoFields.isoMonth); | ||
assert.sameValue(isoDay, isoFields.isoDay); | ||
} |