mirror of
https://github.com/tc39/test262.git
synced 2025-09-24 10:38:30 +02:00
Fix up calendar tests that rely on eras (#4558)
* Fix up calendar tests that rely on eras * remove islamic
This commit is contained in:
parent
f4864f76b2
commit
baa48a416c
@ -61,65 +61,63 @@ var TemporalHelpers = {
|
||||
*/
|
||||
CalendarEras: {
|
||||
buddhist: [
|
||||
{ era: "buddhist", aliases: ["be"] },
|
||||
],
|
||||
chinese: [
|
||||
{ era: "chinese" },
|
||||
{ era: "be" },
|
||||
],
|
||||
coptic: [
|
||||
{ era: "coptic" },
|
||||
{ era: "coptic-inverse" },
|
||||
],
|
||||
dangi: [
|
||||
{ era: "dangi" },
|
||||
{ era: "am" },
|
||||
],
|
||||
ethiopic: [
|
||||
{ era: "ethiopic", aliases: ["incar"] },
|
||||
{ era: "ethioaa", aliases: ["ethiopic-amete-alem", "mundi"] },
|
||||
{ era: "aa", aliases: ["mundi"] },
|
||||
{ era: "am", aliases: ["incar"] },
|
||||
],
|
||||
ethioaa: [
|
||||
{ era: "ethioaa", aliases: ["ethiopic-amete-alem", "mundi"] },
|
||||
{ era: "aa", aliases: ["mundi"] },
|
||||
],
|
||||
gregory: [
|
||||
{ era: "gregory", aliases: ["ce", "ad"] },
|
||||
{ era: "gregory-inverse", aliases: ["bc", "bce"] },
|
||||
{ era: "bce", aliases: ["bc"] },
|
||||
{ era: "ce", aliases: ["ad"] },
|
||||
],
|
||||
hebrew: [
|
||||
{ era: "hebrew", aliases: ["am"] },
|
||||
{ era: "am" },
|
||||
],
|
||||
indian: [
|
||||
{ era: "indian", aliases: ["saka"] },
|
||||
{ era: "shaka" },
|
||||
],
|
||||
islamic: [
|
||||
{ era: "islamic", aliases: ["ah"] },
|
||||
{ era: "ah" },
|
||||
{ era: "bh" },
|
||||
],
|
||||
"islamic-civil": [
|
||||
{ era: "islamic-civil", aliases: ["islamicc", "ah"] },
|
||||
{ era: "bh" },
|
||||
{ era: "ah" },
|
||||
],
|
||||
"islamic-rgsa": [
|
||||
{ era: "islamic-rgsa", aliases: ["ah"] },
|
||||
{ era: "bh" },
|
||||
{ era: "ah" },
|
||||
],
|
||||
"islamic-tbla": [
|
||||
{ era: "islamic-tbla", aliases: ["ah"] },
|
||||
{ era: "bh" },
|
||||
{ era: "ah" },
|
||||
],
|
||||
"islamic-umalqura": [
|
||||
{ era: "islamic-umalqura", aliases: ["ah"] },
|
||||
{ era: "bh" },
|
||||
{ era: "ah" },
|
||||
],
|
||||
japanese: [
|
||||
{ era: "bce", aliases: ["bc"] },
|
||||
{ era: "ce", aliases: ["ad"] },
|
||||
{ era: "heisei" },
|
||||
{ era: "japanese", aliases: ["gregory", "ad", "ce"] },
|
||||
{ era: "japanese-inverse", aliases: ["gregory-inverse", "bc", "bce"] },
|
||||
{ era: "meiji" },
|
||||
{ era: "reiwa" },
|
||||
{ era: "showa" },
|
||||
{ era: "taisho" },
|
||||
],
|
||||
persian: [
|
||||
{ era: "persian", aliases: ["ap"] },
|
||||
{ era: "ap" },
|
||||
],
|
||||
roc: [
|
||||
{ era: "roc", aliases: ["minguo"] },
|
||||
{ era: "roc-inverse", aliases: ["before-roc"] },
|
||||
{ era: "broc", aliases: ["before-roc", "minguo-qian"] },
|
||||
],
|
||||
},
|
||||
|
||||
|
@ -27,22 +27,22 @@ assert.throws(TypeError, () => Temporal.PlainDate.from({
|
||||
calendar: "iso8601",
|
||||
}), "era and eraYear cannot replace year for calendar not using eras (iso8601)");
|
||||
|
||||
const resultHebrew = Temporal.PlainDate.from({
|
||||
const resultChinese = Temporal.PlainDate.from({
|
||||
era: "foobar",
|
||||
eraYear: 1,
|
||||
year: 5780,
|
||||
year: 2025,
|
||||
monthCode: "M01",
|
||||
day: 1,
|
||||
calendar: "hebrew",
|
||||
calendar: "chinese",
|
||||
});
|
||||
TemporalHelpers.assertPlainDate(resultHebrew, 5780, 1, "M01", 1,
|
||||
"era and eraYear are ignored for calendar not using eras (Hebrew)");
|
||||
assert.sameValue(resultHebrew.calendarId, "hebrew");
|
||||
TemporalHelpers.assertPlainDate(resultChinese, 2025, 1, "M01", 1,
|
||||
"era and eraYear are ignored for calendar not using eras (Chinese)");
|
||||
assert.sameValue(resultChinese.calendarId, "chinese");
|
||||
|
||||
assert.throws(TypeError, () => Temporal.PlainDate.from({
|
||||
era: "foobar",
|
||||
eraYear: 1,
|
||||
monthCode: "M01",
|
||||
day: 1,
|
||||
calendar: "hebrew",
|
||||
}), "era and eraYear cannot replace year for calendar not using eras (Hebrew)");
|
||||
calendar: "chinese",
|
||||
}), "era and eraYear cannot replace year for calendar not using eras (Chinese)");
|
||||
|
@ -10,7 +10,7 @@ features: [Temporal]
|
||||
|
||||
const date1 = Temporal.PlainDate.from({
|
||||
calendar: "gregory",
|
||||
era: "ce",
|
||||
era: "ad",
|
||||
eraYear: 2024,
|
||||
year: 2024,
|
||||
month: 1,
|
||||
@ -19,13 +19,13 @@ const date1 = Temporal.PlainDate.from({
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date1,
|
||||
2024, 1, "M01", 1,
|
||||
"'ce' is accepted as alias for 'gregory'",
|
||||
"gregory", 2024
|
||||
"'ad' is accepted as alias for 'ce'",
|
||||
"ce", 2024
|
||||
);
|
||||
|
||||
const date2 = Temporal.PlainDate.from({
|
||||
calendar: "gregory",
|
||||
era: "bce",
|
||||
era: "bc",
|
||||
eraYear: 44,
|
||||
year: -43,
|
||||
month: 3,
|
||||
@ -34,6 +34,6 @@ const date2 = Temporal.PlainDate.from({
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date2,
|
||||
-43, 3, "M03", 15,
|
||||
"'bce' is accepted as alias for 'gregory-inverse'",
|
||||
"gregory-inverse", 44
|
||||
"'bc' is accepted as alias for 'bce'",
|
||||
"bce", 44
|
||||
);
|
||||
|
@ -27,22 +27,22 @@ assert.throws(TypeError, () => Temporal.PlainDateTime.from({
|
||||
calendar: "iso8601",
|
||||
}), "era and eraYear cannot replace year for calendar not using eras (iso8601)");
|
||||
|
||||
const resultHebrew = Temporal.PlainDateTime.from({
|
||||
const resultChinese = Temporal.PlainDateTime.from({
|
||||
era: "foobar",
|
||||
eraYear: 1,
|
||||
year: 5780,
|
||||
year: 2025,
|
||||
monthCode: "M01",
|
||||
day: 1,
|
||||
calendar: "hebrew",
|
||||
calendar: "chinese",
|
||||
});
|
||||
TemporalHelpers.assertPlainDateTime(resultHebrew, 5780, 1, "M01", 1, 0, 0, 0, 0, 0, 0,
|
||||
"era and eraYear are ignored for calendar not using eras (Hebrew)");
|
||||
assert.sameValue(resultHebrew.calendarId, "hebrew");
|
||||
TemporalHelpers.assertPlainDateTime(resultChinese, 2025, 1, "M01", 1, 0, 0, 0, 0, 0, 0,
|
||||
"era and eraYear are ignored for calendar not using eras (Chinese)");
|
||||
assert.sameValue(resultChinese.calendarId, "chinese");
|
||||
|
||||
assert.throws(TypeError, () => Temporal.PlainDateTime.from({
|
||||
era: "foobar",
|
||||
eraYear: 1,
|
||||
monthCode: "M01",
|
||||
day: 1,
|
||||
calendar: "hebrew",
|
||||
}), "era and eraYear cannot replace year for calendar not using eras (Hebrew)");
|
||||
calendar: "chinese",
|
||||
}), "era and eraYear cannot replace year for calendar not using eras (Chinese)");
|
||||
|
@ -10,7 +10,7 @@ features: [Temporal]
|
||||
|
||||
const date1 = Temporal.PlainDateTime.from({
|
||||
calendar: "gregory",
|
||||
era: "ce",
|
||||
era: "ad",
|
||||
eraYear: 2024,
|
||||
year: 2024,
|
||||
month: 1,
|
||||
@ -19,13 +19,13 @@ const date1 = Temporal.PlainDateTime.from({
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date1,
|
||||
2024, 1, "M01", 1, 0, 0, 0, 0, 0, 0,
|
||||
"'ce' is accepted as alias for 'gregory'",
|
||||
"gregory", 2024
|
||||
"'ad' is accepted as alias for 'ce'",
|
||||
"ce", 2024
|
||||
);
|
||||
|
||||
const date2 = Temporal.PlainDateTime.from({
|
||||
calendar: "gregory",
|
||||
era: "bce",
|
||||
era: "bc",
|
||||
eraYear: 44,
|
||||
year: -43,
|
||||
month: 3,
|
||||
@ -34,6 +34,6 @@ const date2 = Temporal.PlainDateTime.from({
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date2,
|
||||
-43, 3, "M03", 15, 0, 0, 0, 0, 0, 0,
|
||||
"'bce' is accepted as alias for 'gregory-inverse'",
|
||||
"gregory-inverse", 44
|
||||
"'bc' is accepted as alias for 'bce'",
|
||||
"bce", 44
|
||||
);
|
||||
|
@ -18,13 +18,13 @@ const result = Temporal.PlainMonthDay.from({
|
||||
TemporalHelpers.assertPlainMonthDay(result, "M01", 1,
|
||||
"era and eraYear are ignored for calendar not using eras (iso8601)");
|
||||
|
||||
const resultHebrew = Temporal.PlainMonthDay.from({
|
||||
const resultChinese = Temporal.PlainMonthDay.from({
|
||||
era: "foobar",
|
||||
eraYear: 1,
|
||||
monthCode: "M01",
|
||||
day: 1,
|
||||
calendar: "hebrew",
|
||||
calendar: "chinese",
|
||||
});
|
||||
TemporalHelpers.assertPlainMonthDay(resultHebrew, "M01", 1,
|
||||
"era and eraYear are ignored for calendar not using eras (Hebrew)");
|
||||
assert.sameValue(resultHebrew.calendarId, "hebrew");
|
||||
TemporalHelpers.assertPlainMonthDay(resultChinese, "M01", 1,
|
||||
"era and eraYear are ignored for calendar not using eras (Chinese)");
|
||||
assert.sameValue(resultChinese.calendarId, "chinese");
|
||||
|
@ -25,22 +25,22 @@ assert.throws(TypeError, () => Temporal.PlainYearMonth.from({
|
||||
calendar: "iso8601",
|
||||
}), "era and eraYear cannot replace year for calendar not using eras (iso8601)");
|
||||
|
||||
const resultHebrew = Temporal.PlainYearMonth.from({
|
||||
const resultChinese = Temporal.PlainYearMonth.from({
|
||||
era: "foobar",
|
||||
eraYear: 1,
|
||||
year: 5780,
|
||||
year: 2025,
|
||||
monthCode: "M01",
|
||||
calendar: "hebrew",
|
||||
calendar: "chinese",
|
||||
});
|
||||
TemporalHelpers.assertPlainYearMonth(resultHebrew, 5780, 1, "M01",
|
||||
"era and eraYear are ignored for calendar not using eras (Hebrew)",
|
||||
undefined, undefined, 30);
|
||||
assert.sameValue(resultHebrew.calendarId, "hebrew");
|
||||
TemporalHelpers.assertPlainYearMonth(resultChinese, 2025, 1, "M01",
|
||||
"era and eraYear are ignored for calendar not using eras (Chinese)",
|
||||
undefined, undefined, 29);
|
||||
assert.sameValue(resultChinese.calendarId, "chinese");
|
||||
|
||||
assert.throws(TypeError, () => Temporal.PlainYearMonth.from({
|
||||
era: "foobar",
|
||||
eraYear: 1,
|
||||
monthCode: "M01",
|
||||
day: 1,
|
||||
calendar: "hebrew",
|
||||
}), "era and eraYear cannot replace year for calendar not using eras (Hebrew)");
|
||||
calendar: "chinese",
|
||||
}), "era and eraYear cannot replace year for calendar not using eras (Chinese)");
|
||||
|
@ -10,7 +10,7 @@ features: [Temporal]
|
||||
|
||||
const date1 = Temporal.PlainYearMonth.from({
|
||||
calendar: "gregory",
|
||||
era: "ce",
|
||||
era: "ad",
|
||||
eraYear: 2024,
|
||||
year: 2024,
|
||||
month: 1,
|
||||
@ -18,13 +18,13 @@ const date1 = Temporal.PlainYearMonth.from({
|
||||
TemporalHelpers.assertPlainYearMonth(
|
||||
date1,
|
||||
2024, 1, "M01",
|
||||
"'ce' is accepted as alias for 'gregory'",
|
||||
"gregory", 2024
|
||||
"'ad' is accepted as alias for 'ce'",
|
||||
"ce", 2024
|
||||
);
|
||||
|
||||
const date2 = Temporal.PlainYearMonth.from({
|
||||
calendar: "gregory",
|
||||
era: "bce",
|
||||
era: "bc",
|
||||
eraYear: 44,
|
||||
year: -43,
|
||||
month: 3,
|
||||
@ -32,6 +32,6 @@ const date2 = Temporal.PlainYearMonth.from({
|
||||
TemporalHelpers.assertPlainYearMonth(
|
||||
date2,
|
||||
-43, 3, "M03",
|
||||
"'bce' is accepted as alias for 'gregory-inverse'",
|
||||
"gregory-inverse", 44
|
||||
"'bc' is accepted as alias for 'bce'",
|
||||
"bce", 44
|
||||
);
|
||||
|
@ -16,7 +16,7 @@ TemporalHelpers.assertPlainYearMonth(
|
||||
result4,
|
||||
5782, 4, "M04",
|
||||
"reference day is the first of the calendar month even if day is given",
|
||||
/* era = */ undefined, /* era year = */ undefined, /* reference day = */ 5
|
||||
"am", /* era year = */ 5782, /* reference day = */ 5
|
||||
);
|
||||
const isoYearMonth = result4.toString().slice(0, 7);
|
||||
assert.sameValue(isoYearMonth, "2021-12", "Tevet 5782 begins in ISO 2021-12");
|
||||
@ -26,7 +26,7 @@ TemporalHelpers.assertPlainYearMonth(
|
||||
result5,
|
||||
5783, 6, "M06",
|
||||
"month code M05L does not exist in year 5783 (overflow constrain); Hebrew calendar constrains Adar I to Adar",
|
||||
/* era = */ undefined, /* era year = */ undefined, /* reference day = */ 22
|
||||
"am", /* era year = */ 5783, /* reference day = */ 22
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
@ -40,7 +40,7 @@ TemporalHelpers.assertPlainYearMonth(
|
||||
result6,
|
||||
5783, 12, "M12",
|
||||
"month 13 does not exist in year 5783 (overflow constrain)",
|
||||
/* era = */ undefined, /* era year = */ undefined, /* reference day = */ 18
|
||||
"am", /* era year = */ 5783, /* reference day = */ 18
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
@ -54,7 +54,7 @@ TemporalHelpers.assertPlainYearMonth(
|
||||
result7,
|
||||
5782, 4, "M04",
|
||||
"reference day is set correctly even if day is out of range (overflow constrain)",
|
||||
/* era = */ undefined, /* era year = */ undefined, /* reference day = */ 5
|
||||
"am", /* era year = */ 5782, /* reference day = */ 5
|
||||
);
|
||||
|
||||
const result8 = Temporal.PlainYearMonth.from({ year: 5782, monthCode: "M04", day: 50, calendar: "hebrew" }, { overflow: "reject" });
|
||||
@ -62,5 +62,5 @@ TemporalHelpers.assertPlainYearMonth(
|
||||
result8,
|
||||
5782, 4, "M04",
|
||||
"reference day is set correctly even if day is out of range (overflow reject)",
|
||||
/* era = */ undefined, /* era year = */ undefined, /* reference day = */ 5
|
||||
"am", /* era year = */ 5782, /* reference day = */ 5
|
||||
);
|
||||
|
@ -11,4 +11,4 @@ features: [Temporal]
|
||||
const apr2000 = new Temporal.PlainYearMonth(2000, 4, "gregory");
|
||||
|
||||
TemporalHelpers.assertPlainYearMonth(apr2000.with({year: -271821}),
|
||||
-271821, 4, "M04", "", "gregory-inverse", 271822);
|
||||
-271821, 4, "M04", "", "bce", 271822);
|
||||
|
@ -28,18 +28,18 @@ assert.throws(TypeError, () => Temporal.ZonedDateTime.from({
|
||||
calendar: "iso8601",
|
||||
}), "era and eraYear cannot replace year for calendar not using eras (iso8601)");
|
||||
|
||||
const resultHebrew = Temporal.ZonedDateTime.from({
|
||||
const resultChinese = Temporal.ZonedDateTime.from({
|
||||
era: "foobar",
|
||||
eraYear: 1,
|
||||
year: 5730,
|
||||
monthCode: "M04",
|
||||
day: 23,
|
||||
year: 1969,
|
||||
monthCode: "M11",
|
||||
day: 24,
|
||||
timeZone: "UTC",
|
||||
calendar: "hebrew",
|
||||
calendar: "chinese",
|
||||
});
|
||||
assert.sameValue(resultHebrew.epochNanoseconds, 0n,
|
||||
"era and eraYear are ignored for calendar not using eras (Hebrew)");
|
||||
assert.sameValue(resultHebrew.calendarId, "hebrew");
|
||||
assert.sameValue(resultChinese.epochNanoseconds, 0n,
|
||||
"era and eraYear are ignored for calendar not using eras (Chinese)");
|
||||
assert.sameValue(resultChinese.calendarId, "chinese");
|
||||
|
||||
assert.throws(TypeError, () => Temporal.ZonedDateTime.from({
|
||||
era: "foobar",
|
||||
@ -47,5 +47,5 @@ assert.throws(TypeError, () => Temporal.ZonedDateTime.from({
|
||||
monthCode: "M01",
|
||||
day: 1,
|
||||
timeZone: "UTC",
|
||||
calendar: "hebrew",
|
||||
}), "era and eraYear cannot replace year for calendar not using eras (Hebrew)");
|
||||
calendar: "chinese",
|
||||
}), "era and eraYear cannot replace year for calendar not using eras (Chinese)");
|
||||
|
@ -9,22 +9,22 @@ features: [Temporal]
|
||||
|
||||
const date1 = Temporal.ZonedDateTime.from({
|
||||
calendar: "gregory",
|
||||
era: "ce",
|
||||
era: "ad",
|
||||
eraYear: 2024,
|
||||
year: 2024,
|
||||
month: 1,
|
||||
day: 1,
|
||||
timeZone: "UTC",
|
||||
});
|
||||
assert.sameValue(date1.era, "gregory", "'ce' is accepted as alias for 'gregory'");
|
||||
assert.sameValue(date1.era, "ce", "'ad' is accepted as alias for 'ce'");
|
||||
|
||||
const date2 = Temporal.ZonedDateTime.from({
|
||||
calendar: "gregory",
|
||||
era: "bce",
|
||||
era: "bc",
|
||||
eraYear: 44,
|
||||
year: -43,
|
||||
month: 3,
|
||||
day: 15,
|
||||
timeZone: "Europe/Rome",
|
||||
});
|
||||
assert.sameValue(date2.era, "gregory-inverse", "'bce' is accepted as alias for 'gregory-inverse'");
|
||||
assert.sameValue(date2.era, "bce", "'bc' is accepted as alias for 'bce'");
|
||||
|
@ -7,52 +7,6 @@ description: Islamic calendar "islamic".
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const calendar = "islamic";
|
||||
|
||||
// Test data obtained from ICU.
|
||||
const choices = [
|
||||
// Approximations of the observational Islamic calendar as computed by ICU4C.
|
||||
{
|
||||
inLeapYear: false,
|
||||
daysInYear: 354,
|
||||
daysInMonth12: 29,
|
||||
isoDate: "2023-07-18",
|
||||
},
|
||||
|
||||
// Approximations of the observational Islamic calendar as computed by ICU4X.
|
||||
{
|
||||
inLeapYear: true,
|
||||
daysInYear: 355,
|
||||
daysInMonth12: 30,
|
||||
isoDate: "2023-07-19",
|
||||
}
|
||||
];
|
||||
|
||||
const year = 1445;
|
||||
const date = Temporal.PlainDate.from({ year, month: 1, day: 1, calendar });
|
||||
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);
|
||||
|
||||
// Match the possible choice by comparing the ISO date value.
|
||||
const choice = choices.find(({ isoDate }) => {
|
||||
return date.toString().startsWith(isoDate);
|
||||
});
|
||||
assert(choice !== undefined, `No applicable choice found for calendar: ${calendar}`);
|
||||
|
||||
const { inLeapYear, daysInYear, daysInMonth12, isoDate } = choice;
|
||||
|
||||
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(date.toString(), `${isoDate}[u-ca=${calendar}]`, "ISO reference date");
|
||||
assert.throws(RangeError, function () {
|
||||
Temporal.PlainDate.from({ year, month: 1, day: 1, calendar });
|
||||
}, "fallback for calendar ID 'islamic' only supported in Intl.DateTimeFormat constructor, not Temporal");
|
||||
|
@ -51,6 +51,8 @@ compareFormatToPartsSnapshot("0001-01-01T00:00Z", {
|
||||
|
||||
var fromWithCases = {
|
||||
year2000: {
|
||||
era: "be",
|
||||
eraYear: 2543,
|
||||
year: 2543,
|
||||
month: 1,
|
||||
monthCode: "M01",
|
||||
@ -123,13 +125,17 @@ var durationCases = {
|
||||
days: {
|
||||
duration: { days: 280 },
|
||||
result: {
|
||||
era: "be",
|
||||
year: 2555,
|
||||
eraYear: 2555,
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: 7,
|
||||
},
|
||||
startDate: {
|
||||
era: "be",
|
||||
year: 2555,
|
||||
eraYear: 2555,
|
||||
month: 1,
|
||||
day: 1
|
||||
}
|
||||
@ -137,7 +143,9 @@ var durationCases = {
|
||||
weeks: {
|
||||
duration: { weeks: 40 },
|
||||
result: {
|
||||
era: "be",
|
||||
year: 2555,
|
||||
eraYear: 2555,
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: 7,
|
||||
@ -151,7 +159,9 @@ var durationCases = {
|
||||
months: {
|
||||
duration: { months: 6 },
|
||||
result: {
|
||||
era: "be",
|
||||
year: 2556,
|
||||
eraYear: 2556,
|
||||
month: 6,
|
||||
monthCode: "M06",
|
||||
day: 1,
|
||||
@ -169,7 +179,9 @@ var durationCases = {
|
||||
days: 17
|
||||
},
|
||||
result: {
|
||||
era: "be",
|
||||
year: 2559,
|
||||
eraYear: 2559,
|
||||
month: 6,
|
||||
monthCode: "M06",
|
||||
day: 18,
|
||||
|
@ -40,7 +40,7 @@ compareFormatToPartsSnapshot("0001-01-01T00:00Z", {
|
||||
|
||||
var fromWithCases = {
|
||||
year2000: {
|
||||
era: "coptic",
|
||||
era: "am",
|
||||
eraYear: 1716,
|
||||
year: 1716,
|
||||
month: 4,
|
||||
@ -48,8 +48,8 @@ var fromWithCases = {
|
||||
day: 22,
|
||||
},
|
||||
year1: {
|
||||
era: "coptic-inverse",
|
||||
eraYear: 284,
|
||||
era: "am",
|
||||
eraYear: -283,
|
||||
year: -283,
|
||||
month: 5,
|
||||
monthCode: "M05",
|
||||
@ -124,7 +124,7 @@ var durationCases = {
|
||||
duration: { days: 280 },
|
||||
result: {
|
||||
eraYear: 2000,
|
||||
era: "coptic",
|
||||
era: "am",
|
||||
year: 2000,
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
@ -140,7 +140,7 @@ var durationCases = {
|
||||
duration: { weeks: 40 },
|
||||
result: {
|
||||
eraYear: 2000,
|
||||
era: "coptic",
|
||||
era: "am",
|
||||
year: 2000,
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
@ -155,7 +155,7 @@ var durationCases = {
|
||||
months: {
|
||||
duration: { months: 6 },
|
||||
result: {
|
||||
era: "coptic",
|
||||
era: "am",
|
||||
eraYear: 2001,
|
||||
year: 2001,
|
||||
month: 5,
|
||||
@ -175,7 +175,7 @@ var durationCases = {
|
||||
days: 17
|
||||
},
|
||||
result: {
|
||||
era: "coptic",
|
||||
era: "am",
|
||||
eraYear: 2001,
|
||||
year: 2001,
|
||||
month: 5,
|
||||
|
@ -41,12 +41,16 @@ compareFormatToPartsSnapshot("0001-01-01T00:00Z", {
|
||||
var fromWithCases = {
|
||||
year2000: {
|
||||
year: 7492,
|
||||
eraYear: 7492,
|
||||
era: "aa",
|
||||
month: 4,
|
||||
monthCode: "M04",
|
||||
day: 22,
|
||||
},
|
||||
year1: {
|
||||
year: 5493,
|
||||
eraYear: 5493,
|
||||
era: "aa",
|
||||
month: 5,
|
||||
monthCode: "M05",
|
||||
day: 8,
|
||||
@ -120,6 +124,8 @@ var durationCases = {
|
||||
duration: { days: 280 },
|
||||
result: {
|
||||
year: 2000,
|
||||
eraYear: 2000,
|
||||
era: "aa",
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: 11,
|
||||
@ -134,6 +140,8 @@ var durationCases = {
|
||||
duration: { weeks: 40 },
|
||||
result: {
|
||||
year: 2000,
|
||||
eraYear: 2000,
|
||||
era: "aa",
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: 11,
|
||||
@ -148,6 +156,8 @@ var durationCases = {
|
||||
duration: { months: 6 },
|
||||
result: {
|
||||
year: 2001,
|
||||
eraYear: 2001,
|
||||
era: "aa",
|
||||
month: 5,
|
||||
monthCode: "M05",
|
||||
day: 1,
|
||||
@ -166,6 +176,8 @@ var durationCases = {
|
||||
},
|
||||
result: {
|
||||
year: 2001,
|
||||
eraYear: 2001,
|
||||
era: "aa",
|
||||
month: 5,
|
||||
monthCode: "M05",
|
||||
day: 18,
|
||||
|
@ -33,7 +33,7 @@ compareFormatToPartsSnapshot("2000-01-01T00:00Z", {
|
||||
|
||||
var fromWithCases = {
|
||||
year2000: {
|
||||
era: "ethiopic",
|
||||
era: "am",
|
||||
eraYear: 1992,
|
||||
month: 4,
|
||||
monthCode: "M04",
|
||||
@ -109,7 +109,7 @@ var durationCases = {
|
||||
days: {
|
||||
duration: { days: 280 },
|
||||
result: {
|
||||
era: "ethiopic",
|
||||
era: "am",
|
||||
eraYear: 2000,
|
||||
year: 2000,
|
||||
month: 10,
|
||||
@ -125,7 +125,7 @@ var durationCases = {
|
||||
weeks: {
|
||||
duration: { weeks: 40 },
|
||||
result: {
|
||||
era: "ethiopic",
|
||||
era: "am",
|
||||
eraYear: 2000,
|
||||
year: 2000,
|
||||
month: 10,
|
||||
@ -141,7 +141,7 @@ var durationCases = {
|
||||
months: {
|
||||
duration: { months: 6 },
|
||||
result: {
|
||||
era: "ethiopic",
|
||||
era: "am",
|
||||
eraYear: 2001,
|
||||
year: 2001,
|
||||
month: 5,
|
||||
@ -161,7 +161,7 @@ var durationCases = {
|
||||
days: 17
|
||||
},
|
||||
result: {
|
||||
era: "ethiopic",
|
||||
era: "am",
|
||||
eraYear: 2001,
|
||||
year: 2001,
|
||||
month: 5,
|
||||
|
@ -38,7 +38,7 @@ compareFormatToPartsSnapshot("0001-01-01T00:00Z", {
|
||||
|
||||
var fromWithCases = {
|
||||
year2000: {
|
||||
era: "gregory",
|
||||
era: "ce",
|
||||
eraYear: 2000,
|
||||
year: 2000,
|
||||
month: 1,
|
||||
@ -46,7 +46,7 @@ var fromWithCases = {
|
||||
day: 1,
|
||||
},
|
||||
year1: {
|
||||
era: "gregory",
|
||||
era: "ce",
|
||||
eraYear: 1,
|
||||
year: 1,
|
||||
month: 1,
|
||||
@ -121,7 +121,7 @@ var durationCases = {
|
||||
days: {
|
||||
duration: { days: 280 },
|
||||
result: {
|
||||
era: "gregory",
|
||||
era: "ce",
|
||||
eraYear: 2000,
|
||||
year: 2000,
|
||||
month: 10,
|
||||
@ -137,7 +137,7 @@ var durationCases = {
|
||||
weeks: {
|
||||
duration: { weeks: 40 },
|
||||
result: {
|
||||
era: "gregory",
|
||||
era: "ce",
|
||||
eraYear: 2000,
|
||||
year: 2000,
|
||||
month: 10,
|
||||
@ -153,7 +153,7 @@ var durationCases = {
|
||||
months: {
|
||||
duration: { months: 6 },
|
||||
result: {
|
||||
era: "gregory",
|
||||
era: "ce",
|
||||
eraYear: 2001,
|
||||
year: 2001,
|
||||
month: 6,
|
||||
@ -173,7 +173,7 @@ var durationCases = {
|
||||
days: 17
|
||||
},
|
||||
result: {
|
||||
era: "gregory",
|
||||
era: "ce",
|
||||
eraYear: 2001,
|
||||
year: 2001,
|
||||
month: 6,
|
||||
|
@ -39,12 +39,16 @@ compareFormatToPartsSnapshot("0001-01-01T00:00Z", {
|
||||
var fromWithCases = {
|
||||
year2000: {
|
||||
year: 5760,
|
||||
eraYear: 5760,
|
||||
era: "am",
|
||||
month: 4,
|
||||
monthCode: "M04",
|
||||
day: 23
|
||||
},
|
||||
year1: {
|
||||
year: 3761,
|
||||
eraYear: 3761,
|
||||
era: "am",
|
||||
month: 4,
|
||||
monthCode: "M04",
|
||||
day: 18
|
||||
@ -118,6 +122,8 @@ var durationCases = {
|
||||
duration: { days: 280 },
|
||||
result: {
|
||||
year: 2000,
|
||||
eraYear: 2000,
|
||||
era: "am",
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: 14,
|
||||
@ -132,6 +138,8 @@ var durationCases = {
|
||||
duration: { weeks: 40 },
|
||||
result: {
|
||||
year: 2000,
|
||||
eraYear: 2000,
|
||||
era: "am",
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: 14,
|
||||
@ -146,6 +154,8 @@ var durationCases = {
|
||||
duration: { months: 6 },
|
||||
result: {
|
||||
year: 2001,
|
||||
eraYear: 2001,
|
||||
era: "am",
|
||||
month: 6,
|
||||
monthCode: "M05L",
|
||||
day: 1,
|
||||
@ -164,6 +174,8 @@ var durationCases = {
|
||||
},
|
||||
result: {
|
||||
year: 2001,
|
||||
eraYear: 2001,
|
||||
era: "am",
|
||||
month: 6,
|
||||
monthCode: "M05L",
|
||||
day: 18,
|
||||
|
@ -41,12 +41,16 @@ compareFormatToPartsSnapshot("0001-01-01T00:00Z", {
|
||||
var fromWithCases = {
|
||||
year2000: {
|
||||
year: 1921,
|
||||
eraYear: 1921,
|
||||
era: "shaka",
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: 11,
|
||||
},
|
||||
year1: {
|
||||
year: -78,
|
||||
eraYear: -78,
|
||||
era: "shaka",
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: 11,
|
||||
@ -120,6 +124,8 @@ var durationCases = {
|
||||
duration: { days: 280 },
|
||||
result: {
|
||||
year: 2000,
|
||||
eraYear: 2000,
|
||||
era: "shaka",
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: 6,
|
||||
@ -134,6 +140,8 @@ var durationCases = {
|
||||
duration: { weeks: 40 },
|
||||
result: {
|
||||
year: 2000,
|
||||
eraYear: 2000,
|
||||
era: "shaka",
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: 6,
|
||||
@ -148,6 +156,8 @@ var durationCases = {
|
||||
duration: { months: 6 },
|
||||
result: {
|
||||
year: 2001,
|
||||
eraYear: 2001,
|
||||
era: "shaka",
|
||||
month: 6,
|
||||
monthCode: "M06",
|
||||
day: 1,
|
||||
@ -166,6 +176,8 @@ var durationCases = {
|
||||
},
|
||||
result: {
|
||||
year: 2001,
|
||||
eraYear: 2001,
|
||||
era: "shaka",
|
||||
month: 6,
|
||||
monthCode: "M06",
|
||||
day: 18,
|
||||
|
@ -41,12 +41,16 @@ compareFormatToPartsSnapshot("0001-01-01T00:00Z", {
|
||||
var fromWithCases = {
|
||||
year2000: {
|
||||
year: 1420,
|
||||
eraYear: 1420,
|
||||
era: "ah",
|
||||
month: 9,
|
||||
monthCode: "M09",
|
||||
day: 24,
|
||||
},
|
||||
year1: {
|
||||
year: -640,
|
||||
eraYear: 641,
|
||||
era: "bh",
|
||||
month: 5,
|
||||
monthCode: "M05",
|
||||
day: 18,
|
||||
@ -120,6 +124,8 @@ var durationCases = {
|
||||
duration: { days: 280 },
|
||||
result: {
|
||||
year: 2000,
|
||||
eraYear: 2000,
|
||||
era: "ah",
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: 15,
|
||||
@ -134,6 +140,8 @@ var durationCases = {
|
||||
duration: { weeks: 40 },
|
||||
result: {
|
||||
year: 2000,
|
||||
eraYear: 2000,
|
||||
era: "ah",
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: 15,
|
||||
@ -148,6 +156,8 @@ var durationCases = {
|
||||
duration: { months: 6 },
|
||||
result: {
|
||||
year: 2001,
|
||||
eraYear: 2001,
|
||||
era: "ah",
|
||||
month: 6,
|
||||
monthCode: "M06",
|
||||
day: 1,
|
||||
@ -166,6 +176,8 @@ var durationCases = {
|
||||
},
|
||||
result: {
|
||||
year: 2001,
|
||||
eraYear: 2001,
|
||||
era: "ah",
|
||||
month: 6,
|
||||
monthCode: "M06",
|
||||
day: 18,
|
||||
|
@ -38,327 +38,4 @@ compareFormatToPartsSnapshot("0001-01-01T00:00Z", {
|
||||
// day: 20,
|
||||
});
|
||||
|
||||
var fromWithCases = {
|
||||
year2000: {
|
||||
year: 1420,
|
||||
month: 9,
|
||||
monthCode: "M09",
|
||||
day: [23, 25],
|
||||
},
|
||||
year1: {
|
||||
year: -640,
|
||||
month: 5,
|
||||
monthCode: "M05",
|
||||
day: [20, 19],
|
||||
}
|
||||
};
|
||||
var dates = {
|
||||
year2000: Temporal.PlainDate.from("2000-01-01"),
|
||||
year1: Temporal.PlainDate.from("0001-01-01")
|
||||
};
|
||||
for (var [name, result] of Object.entries(fromWithCases)) {
|
||||
var date = dates[name];
|
||||
var inCal = date.withCalendar(calendar);
|
||||
|
||||
assert.sameValue(inCal.era, result.era, `${name}: era`);
|
||||
assert.sameValue(inCal.eraYear, result.eraYear, `${name}: eraYear`);
|
||||
assert.sameValue(inCal.year, result.year, `${name}: year`);
|
||||
assert.sameValue(inCal.month, result.month, `${name}: month`);
|
||||
assert.sameValue(inCal.monthCode, result.monthCode, `${name}: monthCode`);
|
||||
assert(result.day.includes(inCal.day), `${name}: day`);
|
||||
|
||||
var dateRoundtrip2 = Temporal.PlainDate.from({
|
||||
calendar,
|
||||
year: result.year,
|
||||
day: inCal.day,
|
||||
monthCode: result.monthCode
|
||||
});
|
||||
assert.sameValue(dateRoundtrip2.toString(), inCal.toString());
|
||||
|
||||
var dateRoundtrip3 = Temporal.PlainDate.from({
|
||||
calendar,
|
||||
year: result.year,
|
||||
day: inCal.day,
|
||||
month: result.month
|
||||
});
|
||||
assert.sameValue(dateRoundtrip3.toString(), inCal.toString());
|
||||
|
||||
var dateRoundtrip4 = Temporal.PlainDate.from({
|
||||
calendar,
|
||||
year: result.year,
|
||||
day: inCal.day,
|
||||
monthCode: result.monthCode
|
||||
});
|
||||
assert.sameValue(dateRoundtrip4.toString(), inCal.toString());
|
||||
|
||||
assert.throws(RangeError, () => Temporal.PlainDate.from({
|
||||
calendar,
|
||||
day: inCal.day,
|
||||
month: result.month === 1 ? 2 : result.month - 1,
|
||||
monthCode: result.monthCode,
|
||||
year: result.year
|
||||
}));
|
||||
|
||||
var afterWithDay = inCal.with({ day: 1 });
|
||||
assert.sameValue(afterWithDay.year, inCal.year, `${name} (after setting day)`);
|
||||
assert.sameValue(afterWithDay.month, inCal.month, `${name} (after setting day)`);
|
||||
assert.sameValue(afterWithDay.day, 1, `${name} (after setting day)`);
|
||||
|
||||
var afterWithMonth = afterWithDay.with({ month: 1 });
|
||||
assert.sameValue(afterWithMonth.year, inCal.year, `${name} (after setting month)`);
|
||||
assert.sameValue(afterWithMonth.month, 1, `${name} (after setting month)`);
|
||||
assert.sameValue(afterWithMonth.day, 1, `${name} (after setting month)`);
|
||||
|
||||
var afterWithYear = afterWithMonth.with({ year: 2220 });
|
||||
assert.sameValue(afterWithYear.year, 2220, `${name} (after setting year)`);
|
||||
assert.sameValue(afterWithYear.month, 1, `${name} (after setting year)`);
|
||||
assert.sameValue(afterWithYear.day, 1, `${name} (after setting year)`);
|
||||
}
|
||||
|
||||
var durationCases = {
|
||||
days: {
|
||||
duration: { days: 280 },
|
||||
result: {
|
||||
year: 1426,
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: [15, 14],
|
||||
},
|
||||
startDate: {
|
||||
year: 1426,
|
||||
month: 1,
|
||||
day: 1
|
||||
}
|
||||
},
|
||||
weeks: {
|
||||
duration: { weeks: 40 },
|
||||
result: {
|
||||
year: 1426,
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: [15, 14],
|
||||
},
|
||||
startDate: {
|
||||
year: 1426,
|
||||
month: 1,
|
||||
day: 1
|
||||
}
|
||||
},
|
||||
months: {
|
||||
duration: { months: 6 },
|
||||
result: {
|
||||
year: 1427,
|
||||
month: 6,
|
||||
monthCode: "M06",
|
||||
day: [1, 2],
|
||||
},
|
||||
startDate: {
|
||||
year: 1426,
|
||||
month: 12,
|
||||
day: 1
|
||||
}
|
||||
},
|
||||
years: {
|
||||
duration: {
|
||||
years: 3,
|
||||
months: 6,
|
||||
days: 17
|
||||
},
|
||||
result: {
|
||||
year: 1427,
|
||||
month: 6,
|
||||
monthCode: "M06",
|
||||
day: [18, 19],
|
||||
},
|
||||
startDate: {
|
||||
year: 1423,
|
||||
monthCode: "M12",
|
||||
day: 1
|
||||
}
|
||||
}
|
||||
};
|
||||
for (var [unit, {duration, result, startDate}] of Object.entries(durationCases)) {
|
||||
duration = Temporal.Duration.from(duration);
|
||||
|
||||
var start = Temporal.PlainDate.from({
|
||||
...startDate,
|
||||
calendar
|
||||
});
|
||||
|
||||
var end = start.add(duration);
|
||||
assert.sameValue(end.era, result.era, `${unit}`);
|
||||
assert.sameValue(end.eraYear, result.eraYear, `${unit}`);
|
||||
assert.sameValue(end.year, result.year, `${unit}`);
|
||||
assert.sameValue(end.month, result.month, `${unit}`);
|
||||
assert.sameValue(end.monthCode, result.monthCode, `${unit}`);
|
||||
assert(result.day.includes(end.day), `${unit}`);
|
||||
|
||||
var calculatedStart = end.subtract(duration);
|
||||
var expectedCalculatedStart = start;
|
||||
assert.sameValue(calculatedStart.toString(), expectedCalculatedStart.toString(), `${unit}`);
|
||||
|
||||
var diff = start.until(end, { largestUnit: unit });
|
||||
assert.sameValue(diff.toString(), duration.toString(), `${unit}`);
|
||||
|
||||
if (unit === "months") {
|
||||
var startYesterday = start.subtract({ days: 1 });
|
||||
var endYesterday = startYesterday.add(duration);
|
||||
assert.sameValue(endYesterday.day, Math.min(startYesterday.day, endYesterday.daysInMonth), `${unit}`);
|
||||
|
||||
var endYesterdayNextDay = endYesterday.add({ days: 1 });
|
||||
while (endYesterdayNextDay.day !== 1) {
|
||||
endYesterdayNextDay = endYesterdayNextDay.add({ days: 1 });
|
||||
}
|
||||
assert.sameValue(endYesterdayNextDay.era, result.era, `${unit}`);
|
||||
assert.sameValue(endYesterdayNextDay.eraYear, result.eraYear, `${unit}`);
|
||||
assert.sameValue(endYesterdayNextDay.year, result.year, `${unit}`);
|
||||
assert.sameValue(endYesterdayNextDay.month, result.month, `${unit}`);
|
||||
assert.sameValue(endYesterdayNextDay.monthCode, result.monthCode, `${unit}`);
|
||||
assert(result.day.includes(endYesterdayNextDay.day), `${unit}`);
|
||||
|
||||
var endReverse = endYesterdayNextDay.subtract({ days: 1 });
|
||||
var startReverse = endReverse.subtract(duration);
|
||||
assert.sameValue(startReverse.day, Math.min(endReverse.day, startReverse.daysInMonth));
|
||||
|
||||
var startReverseNextDay = startReverse.add({ days: 1 });
|
||||
while (startReverseNextDay.day !== 1) {
|
||||
startReverseNextDay = startReverseNextDay.add({ days: 1 });
|
||||
}
|
||||
assert.sameValue(startReverseNextDay.era, start.era, `${unit}`);
|
||||
assert.sameValue(startReverseNextDay.eraYear, start.eraYear, `${unit}`);
|
||||
assert.sameValue(startReverseNextDay.year, start.year, `${unit}`);
|
||||
assert.sameValue(startReverseNextDay.month, start.month, `${unit}`);
|
||||
assert.sameValue(startReverseNextDay.monthCode, start.monthCode, `${unit}`);
|
||||
assert.sameValue(startReverseNextDay.day, start.day, `${unit}`);
|
||||
}
|
||||
}
|
||||
|
||||
var daysInMonthCases = [
|
||||
{
|
||||
year: 1424,
|
||||
leap: false,
|
||||
days: [[
|
||||
29,
|
||||
30,
|
||||
30,
|
||||
29,
|
||||
30,
|
||||
29,
|
||||
30,
|
||||
29,
|
||||
29,
|
||||
30,
|
||||
29,
|
||||
30
|
||||
], [
|
||||
30,
|
||||
29,
|
||||
30,
|
||||
29,
|
||||
30,
|
||||
29,
|
||||
30,
|
||||
29,
|
||||
30,
|
||||
29,
|
||||
30,
|
||||
29
|
||||
]]
|
||||
},
|
||||
];
|
||||
for (var {year, leap, days} of daysInMonthCases) {
|
||||
var date = Temporal.PlainDate.from({
|
||||
year,
|
||||
month: 1,
|
||||
day: 1,
|
||||
calendar
|
||||
});
|
||||
assert.sameValue(date.inLeapYear, leap);
|
||||
|
||||
var {monthsInYear} = date;
|
||||
assert.sameValue(monthsInYear, days[0].length);
|
||||
|
||||
for (var i = monthsInYear, monthStart = undefined, daysIndex = undefined; i >= 1; i--) {
|
||||
monthStart = monthStart ? monthStart.add({ months: -1 }) : date.add({ months: monthsInYear - 1 });
|
||||
|
||||
var {month, monthCode, daysInMonth} = monthStart;
|
||||
assert.sameValue(month, i);
|
||||
if (daysIndex === undefined) {
|
||||
daysIndex = days.findIndex(e => e[i - 1] === daysInMonth);
|
||||
}
|
||||
assert.sameValue(daysInMonth, days[daysIndex][i - 1]);
|
||||
|
||||
assert.sameValue(monthCode.endsWith("L"), false);
|
||||
assert.throws(RangeError, () => monthStart.with({ monthCode: `M${ month.toString().padStart(2, "0") }L` }));
|
||||
assert.throws(RangeError, () => monthStart.with({ monthCode: `M${ month.toString().padStart(2, "0") }L` }, { overflow: "reject" }));
|
||||
|
||||
var oneDayPastMonthEnd = monthStart.with({ day: daysInMonth + 1 });
|
||||
assert.sameValue(oneDayPastMonthEnd.day, daysInMonth);
|
||||
assert.throws(RangeError, () => monthStart.with({ day: daysInMonth + 1 }, { overflow: "reject" }));
|
||||
}
|
||||
}
|
||||
|
||||
var monthDayCases = [
|
||||
{
|
||||
year: 1424,
|
||||
month: 3,
|
||||
monthCode: "M03",
|
||||
day: 30
|
||||
},
|
||||
];
|
||||
for (var {monthCode, month, day, year} of monthDayCases) {
|
||||
var md = Temporal.PlainMonthDay.from({
|
||||
year,
|
||||
month,
|
||||
day,
|
||||
calendar
|
||||
});
|
||||
var isoString = md.toString();
|
||||
|
||||
var mdFromIso = Temporal.PlainMonthDay.from(isoString);
|
||||
assert.sameValue(mdFromIso.toString(), isoString);
|
||||
assert.sameValue(md.monthCode, monthCode);
|
||||
assert.sameValue(md.day, day);
|
||||
|
||||
var md2 = Temporal.PlainMonthDay.from({
|
||||
monthCode,
|
||||
day,
|
||||
calendar
|
||||
});
|
||||
assert.sameValue(md2.monthCode, monthCode);
|
||||
assert.sameValue(md2.day, day);
|
||||
assert.sameValue(md.equals(md2), true);
|
||||
|
||||
assert.throws(RangeError, () => {
|
||||
Temporal.PlainMonthDay.from({
|
||||
monthCode: "M15",
|
||||
day: 1,
|
||||
calendar
|
||||
}, { overflow: "reject" });
|
||||
});
|
||||
|
||||
assert.throws(RangeError, () => {
|
||||
Temporal.PlainMonthDay.from({
|
||||
monthCode: "M15",
|
||||
day: 1,
|
||||
calendar
|
||||
});
|
||||
});
|
||||
|
||||
assert.throws(RangeError, () => {
|
||||
Temporal.PlainMonthDay.from({
|
||||
year,
|
||||
month: 15,
|
||||
day: 1,
|
||||
calendar
|
||||
}, { overflow: "reject" });
|
||||
});
|
||||
|
||||
var constrained = Temporal.PlainMonthDay.from({
|
||||
year,
|
||||
month: 15,
|
||||
day: 1,
|
||||
calendar
|
||||
});
|
||||
assert.sameValue(constrained.monthCode, "M12");
|
||||
}
|
||||
// No Temporal tests; this calendar is not supported in Temporal
|
||||
|
@ -41,12 +41,16 @@ compareFormatToPartsSnapshot("0001-01-01T00:00Z", {
|
||||
var fromWithCases = {
|
||||
year2000: {
|
||||
year: 1420,
|
||||
eraYear: 1420,
|
||||
era: "ah",
|
||||
month: 9,
|
||||
monthCode: "M09",
|
||||
day: 25,
|
||||
},
|
||||
year1: {
|
||||
year: -640,
|
||||
eraYear: 641,
|
||||
era: "bh",
|
||||
month: 5,
|
||||
monthCode: "M05",
|
||||
day: 19,
|
||||
@ -120,6 +124,8 @@ var durationCases = {
|
||||
duration: { days: 280 },
|
||||
result: {
|
||||
year: 2000,
|
||||
eraYear: 2000,
|
||||
era: "ah",
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: 15,
|
||||
@ -134,6 +140,8 @@ var durationCases = {
|
||||
duration: { weeks: 40 },
|
||||
result: {
|
||||
year: 2000,
|
||||
eraYear: 2000,
|
||||
era: "ah",
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: 15,
|
||||
@ -148,6 +156,8 @@ var durationCases = {
|
||||
duration: { months: 6 },
|
||||
result: {
|
||||
year: 2001,
|
||||
eraYear: 2001,
|
||||
era: "ah",
|
||||
month: 6,
|
||||
monthCode: "M06",
|
||||
day: 1,
|
||||
@ -166,6 +176,8 @@ var durationCases = {
|
||||
},
|
||||
result: {
|
||||
year: 2001,
|
||||
eraYear: 2001,
|
||||
era: "ah",
|
||||
month: 6,
|
||||
monthCode: "M06",
|
||||
day: 18,
|
||||
|
@ -41,6 +41,8 @@ compareFormatToPartsSnapshot("0001-01-01T00:00Z", {
|
||||
var fromWithCases = {
|
||||
year2000: {
|
||||
year: 1420,
|
||||
eraYear: 1420,
|
||||
era: "ah",
|
||||
month: 9,
|
||||
monthCode: "M09",
|
||||
day: 24,
|
||||
@ -113,6 +115,8 @@ var durationCases = {
|
||||
duration: { days: 280 },
|
||||
result: {
|
||||
year: 1426,
|
||||
eraYear: 1426,
|
||||
era: "ah",
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: 15,
|
||||
@ -127,6 +131,8 @@ var durationCases = {
|
||||
duration: { weeks: 40 },
|
||||
result: {
|
||||
year: 1426,
|
||||
eraYear: 1426,
|
||||
era: "ah",
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: 15,
|
||||
@ -141,6 +147,8 @@ var durationCases = {
|
||||
duration: { months: 6 },
|
||||
result: {
|
||||
year: 1427,
|
||||
eraYear: 1427,
|
||||
era: "ah",
|
||||
month: 6,
|
||||
monthCode: "M06",
|
||||
day: 1,
|
||||
@ -159,6 +167,8 @@ var durationCases = {
|
||||
},
|
||||
result: {
|
||||
year: 1427,
|
||||
eraYear: 1427,
|
||||
era: "ah",
|
||||
month: 6,
|
||||
monthCode: "M06",
|
||||
day: 18,
|
||||
|
@ -41,324 +41,20 @@ compareFormatToPartsSnapshot("0001-01-01T00:00Z", {
|
||||
var fromWithCases = {
|
||||
year2000: {
|
||||
year: 1420,
|
||||
eraYear: 1420,
|
||||
era: "ah",
|
||||
month: 9,
|
||||
monthCode: "M09",
|
||||
day: [23, 25],
|
||||
},
|
||||
year1: {
|
||||
year: -640,
|
||||
eraYear: 641,
|
||||
era: "bh",
|
||||
month: 5,
|
||||
monthCode: "M05",
|
||||
day: [20, 19],
|
||||
}
|
||||
};
|
||||
var dates = {
|
||||
year2000: Temporal.PlainDate.from("2000-01-01"),
|
||||
year1: Temporal.PlainDate.from("0001-01-01")
|
||||
};
|
||||
for (var [name, result] of Object.entries(fromWithCases)) {
|
||||
var date = dates[name];
|
||||
var inCal = date.withCalendar(calendar);
|
||||
|
||||
assert.sameValue(inCal.era, result.era, `${name}: era`);
|
||||
assert.sameValue(inCal.eraYear, result.eraYear, `${name}: eraYear`);
|
||||
assert.sameValue(inCal.year, result.year, `${name}: year`);
|
||||
assert.sameValue(inCal.month, result.month, `${name}: month`);
|
||||
assert.sameValue(inCal.monthCode, result.monthCode, `${name}: monthCode`);
|
||||
assert(result.day.includes(inCal.day), `${name}: day`);
|
||||
|
||||
var dateRoundtrip2 = Temporal.PlainDate.from({
|
||||
calendar,
|
||||
year: result.year,
|
||||
day: inCal.day,
|
||||
monthCode: result.monthCode
|
||||
});
|
||||
assert.sameValue(dateRoundtrip2.toString(), inCal.toString());
|
||||
|
||||
var dateRoundtrip3 = Temporal.PlainDate.from({
|
||||
calendar,
|
||||
year: result.year,
|
||||
day: inCal.day,
|
||||
month: result.month
|
||||
});
|
||||
assert.sameValue(dateRoundtrip3.toString(), inCal.toString());
|
||||
|
||||
var dateRoundtrip4 = Temporal.PlainDate.from({
|
||||
calendar,
|
||||
year: result.year,
|
||||
day: inCal.day,
|
||||
monthCode: result.monthCode
|
||||
});
|
||||
assert.sameValue(dateRoundtrip4.toString(), inCal.toString());
|
||||
|
||||
assert.throws(RangeError, () => Temporal.PlainDate.from({
|
||||
calendar,
|
||||
day: inCal.day,
|
||||
month: result.month === 1 ? 2 : result.month - 1,
|
||||
monthCode: result.monthCode,
|
||||
year: result.year
|
||||
}));
|
||||
|
||||
var afterWithDay = inCal.with({ day: 1 });
|
||||
assert.sameValue(afterWithDay.year, inCal.year, `${name} (after setting day)`);
|
||||
assert.sameValue(afterWithDay.month, inCal.month, `${name} (after setting day)`);
|
||||
assert.sameValue(afterWithDay.day, 1, `${name} (after setting day)`);
|
||||
|
||||
var afterWithMonth = afterWithDay.with({ month: 1 });
|
||||
assert.sameValue(afterWithMonth.year, inCal.year, `${name} (after setting month)`);
|
||||
assert.sameValue(afterWithMonth.month, 1, `${name} (after setting month)`);
|
||||
assert.sameValue(afterWithMonth.day, 1, `${name} (after setting month)`);
|
||||
|
||||
var afterWithYear = afterWithMonth.with({ year: 2220 });
|
||||
assert.sameValue(afterWithYear.year, 2220, `${name} (after setting year)`);
|
||||
assert.sameValue(afterWithYear.month, 1, `${name} (after setting year)`);
|
||||
assert.sameValue(afterWithYear.day, 1, `${name} (after setting year)`);
|
||||
}
|
||||
|
||||
var durationCases = {
|
||||
days: {
|
||||
duration: { days: 280 },
|
||||
result: {
|
||||
year: 1426,
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: [15, 14],
|
||||
},
|
||||
startDate: {
|
||||
year: 1426,
|
||||
month: 1,
|
||||
day: 1
|
||||
}
|
||||
},
|
||||
weeks: {
|
||||
duration: { weeks: 40 },
|
||||
result: {
|
||||
year: 1426,
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: [15, 14],
|
||||
},
|
||||
startDate: {
|
||||
year: 1426,
|
||||
month: 1,
|
||||
day: 1
|
||||
}
|
||||
},
|
||||
months: {
|
||||
duration: { months: 6 },
|
||||
result: {
|
||||
year: 1427,
|
||||
month: 6,
|
||||
monthCode: "M06",
|
||||
day: [1, 2],
|
||||
},
|
||||
startDate: {
|
||||
year: 1426,
|
||||
month: 12,
|
||||
day: 1
|
||||
}
|
||||
},
|
||||
years: {
|
||||
duration: {
|
||||
years: 3,
|
||||
months: 6,
|
||||
days: 17
|
||||
},
|
||||
result: {
|
||||
year: 1427,
|
||||
month: 6,
|
||||
monthCode: "M06",
|
||||
day: [18, 19],
|
||||
},
|
||||
startDate: {
|
||||
year: 1423,
|
||||
monthCode: "M12",
|
||||
day: 1
|
||||
}
|
||||
}
|
||||
};
|
||||
for (var [unit, {duration, result, startDate}] of Object.entries(durationCases)) {
|
||||
duration = Temporal.Duration.from(duration);
|
||||
|
||||
var start = Temporal.PlainDate.from({
|
||||
...startDate,
|
||||
calendar
|
||||
});
|
||||
|
||||
var end = start.add(duration);
|
||||
assert.sameValue(end.era, result.era, `${unit}`);
|
||||
assert.sameValue(end.eraYear, result.eraYear, `${unit}`);
|
||||
assert.sameValue(end.year, result.year, `${unit}`);
|
||||
assert.sameValue(end.month, result.month, `${unit}`);
|
||||
assert.sameValue(end.monthCode, result.monthCode, `${unit}`);
|
||||
assert(result.day.includes(end.day), `${unit}`);
|
||||
|
||||
var calculatedStart = end.subtract(duration);
|
||||
var expectedCalculatedStart = start;
|
||||
assert.sameValue(calculatedStart.toString(), expectedCalculatedStart.toString(), `${unit}`);
|
||||
|
||||
var diff = start.until(end, { largestUnit: unit });
|
||||
assert.sameValue(diff.toString(), duration.toString(), `${unit}`);
|
||||
|
||||
if (unit === "months") {
|
||||
var startYesterday = start.subtract({ days: 1 });
|
||||
var endYesterday = startYesterday.add(duration);
|
||||
assert.sameValue(endYesterday.day, Math.min(startYesterday.day, endYesterday.daysInMonth), `${unit}`);
|
||||
|
||||
var endYesterdayNextDay = endYesterday.add({ days: 1 });
|
||||
while (endYesterdayNextDay.day !== 1) {
|
||||
endYesterdayNextDay = endYesterdayNextDay.add({ days: 1 });
|
||||
}
|
||||
assert.sameValue(endYesterdayNextDay.era, result.era, `${unit}`);
|
||||
assert.sameValue(endYesterdayNextDay.eraYear, result.eraYear, `${unit}`);
|
||||
assert.sameValue(endYesterdayNextDay.year, result.year, `${unit}`);
|
||||
assert.sameValue(endYesterdayNextDay.month, result.month, `${unit}`);
|
||||
assert.sameValue(endYesterdayNextDay.monthCode, result.monthCode, `${unit}`);
|
||||
assert(result.day.includes(endYesterdayNextDay.day), `${unit}`);
|
||||
|
||||
var endReverse = endYesterdayNextDay.subtract({ days: 1 });
|
||||
var startReverse = endReverse.subtract(duration);
|
||||
assert.sameValue(startReverse.day, Math.min(endReverse.day, startReverse.daysInMonth));
|
||||
|
||||
var startReverseNextDay = startReverse.add({ days: 1 });
|
||||
while (startReverseNextDay.day !== 1) {
|
||||
startReverseNextDay = startReverseNextDay.add({ days: 1 });
|
||||
}
|
||||
assert.sameValue(startReverseNextDay.era, start.era, `${unit}`);
|
||||
assert.sameValue(startReverseNextDay.eraYear, start.eraYear, `${unit}`);
|
||||
assert.sameValue(startReverseNextDay.year, start.year, `${unit}`);
|
||||
assert.sameValue(startReverseNextDay.month, start.month, `${unit}`);
|
||||
assert.sameValue(startReverseNextDay.monthCode, start.monthCode, `${unit}`);
|
||||
assert.sameValue(startReverseNextDay.day, start.day, `${unit}`);
|
||||
}
|
||||
}
|
||||
|
||||
var daysInMonthCases = [
|
||||
{
|
||||
year: 1424,
|
||||
leap: false,
|
||||
days: [[
|
||||
29,
|
||||
30,
|
||||
30,
|
||||
29,
|
||||
30,
|
||||
29,
|
||||
30,
|
||||
29,
|
||||
29,
|
||||
30,
|
||||
29,
|
||||
30
|
||||
], [
|
||||
30,
|
||||
29,
|
||||
30,
|
||||
29,
|
||||
30,
|
||||
29,
|
||||
30,
|
||||
29,
|
||||
30,
|
||||
29,
|
||||
30,
|
||||
29
|
||||
]]
|
||||
},
|
||||
];
|
||||
for (var {year, leap, days} of daysInMonthCases) {
|
||||
var date = Temporal.PlainDate.from({
|
||||
year,
|
||||
month: 1,
|
||||
day: 1,
|
||||
calendar
|
||||
});
|
||||
assert.sameValue(date.inLeapYear, leap);
|
||||
|
||||
var {monthsInYear} = date;
|
||||
assert.sameValue(monthsInYear, days[0].length);
|
||||
|
||||
for (var i = monthsInYear, monthStart = undefined, daysIndex = undefined; i >= 1; i--) {
|
||||
monthStart = monthStart ? monthStart.add({ months: -1 }) : date.add({ months: monthsInYear - 1 });
|
||||
|
||||
var {month, monthCode, daysInMonth} = monthStart;
|
||||
assert.sameValue(month, i);
|
||||
if (daysIndex === undefined) {
|
||||
daysIndex = days.findIndex(e => e[i - 1] === daysInMonth);
|
||||
}
|
||||
assert.sameValue(daysInMonth, days[daysIndex][i - 1]);
|
||||
|
||||
assert.sameValue(monthCode.endsWith("L"), false);
|
||||
assert.throws(RangeError, () => monthStart.with({ monthCode: `M${ month.toString().padStart(2, "0") }L` }));
|
||||
assert.throws(RangeError, () => monthStart.with({ monthCode: `M${ month.toString().padStart(2, "0") }L` }, { overflow: "reject" }));
|
||||
|
||||
var oneDayPastMonthEnd = monthStart.with({ day: daysInMonth + 1 });
|
||||
assert.sameValue(oneDayPastMonthEnd.day, daysInMonth);
|
||||
assert.throws(RangeError, () => monthStart.with({ day: daysInMonth + 1 }, { overflow: "reject" }));
|
||||
}
|
||||
}
|
||||
|
||||
var monthDayCases = [
|
||||
{
|
||||
year: 1424,
|
||||
month: 3,
|
||||
monthCode: "M03",
|
||||
day: 30
|
||||
},
|
||||
];
|
||||
for (var {monthCode, month, day, year} of monthDayCases) {
|
||||
var md = Temporal.PlainMonthDay.from({
|
||||
year,
|
||||
month,
|
||||
day,
|
||||
calendar
|
||||
});
|
||||
var isoString = md.toString();
|
||||
|
||||
var mdFromIso = Temporal.PlainMonthDay.from(isoString);
|
||||
assert.sameValue(mdFromIso.toString(), isoString);
|
||||
assert.sameValue(md.monthCode, monthCode);
|
||||
assert.sameValue(md.day, day);
|
||||
|
||||
var md2 = Temporal.PlainMonthDay.from({
|
||||
monthCode,
|
||||
day,
|
||||
calendar
|
||||
});
|
||||
assert.sameValue(md2.monthCode, monthCode);
|
||||
assert.sameValue(md2.day, day);
|
||||
assert.sameValue(md.equals(md2), true);
|
||||
|
||||
assert.throws(RangeError, () => {
|
||||
Temporal.PlainMonthDay.from({
|
||||
monthCode: "M15",
|
||||
day: 1,
|
||||
calendar
|
||||
}, { overflow: "reject" });
|
||||
});
|
||||
|
||||
assert.throws(RangeError, () => {
|
||||
Temporal.PlainMonthDay.from({
|
||||
monthCode: "M15",
|
||||
day: 1,
|
||||
calendar
|
||||
});
|
||||
});
|
||||
|
||||
assert.throws(RangeError, () => {
|
||||
Temporal.PlainMonthDay.from({
|
||||
year,
|
||||
month: 15,
|
||||
day: 1,
|
||||
calendar
|
||||
}, { overflow: "reject" });
|
||||
});
|
||||
|
||||
var constrained = Temporal.PlainMonthDay.from({
|
||||
year,
|
||||
month: 15,
|
||||
day: 1,
|
||||
calendar
|
||||
});
|
||||
assert.sameValue(constrained.monthCode, "M12");
|
||||
}
|
||||
// No Temporal tests; this calendar is not supported in Temporal
|
||||
|
@ -41,12 +41,16 @@ compareFormatToPartsSnapshot("0001-01-01T00:00Z", {
|
||||
var fromWithCases = {
|
||||
year2000: {
|
||||
year: 1420,
|
||||
eraYear: 1420,
|
||||
era: "ah",
|
||||
month: 9,
|
||||
monthCode: "M09",
|
||||
day: 24,
|
||||
},
|
||||
year1: {
|
||||
year: -640,
|
||||
eraYear: 641,
|
||||
era: "bh",
|
||||
month: 5,
|
||||
monthCode: "M05",
|
||||
day: 18,
|
||||
@ -120,6 +124,8 @@ var durationCases = {
|
||||
duration: { days: 280 },
|
||||
result: {
|
||||
year: 2000,
|
||||
eraYear: 2000,
|
||||
era: "ah",
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: 15,
|
||||
@ -134,6 +140,8 @@ var durationCases = {
|
||||
duration: { weeks: 40 },
|
||||
result: {
|
||||
year: 2000,
|
||||
eraYear: 2000,
|
||||
era: "ah",
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: 15,
|
||||
@ -148,6 +156,8 @@ var durationCases = {
|
||||
duration: { months: 6 },
|
||||
result: {
|
||||
year: 2001,
|
||||
eraYear: 2001,
|
||||
era: "ah",
|
||||
month: 6,
|
||||
monthCode: "M06",
|
||||
day: 1,
|
||||
@ -166,6 +176,8 @@ var durationCases = {
|
||||
},
|
||||
result: {
|
||||
year: 2001,
|
||||
eraYear: 2001,
|
||||
era: "ah",
|
||||
month: 6,
|
||||
monthCode: "M06",
|
||||
day: 18,
|
||||
|
@ -41,12 +41,16 @@ compareFormatToPartsSnapshot("0001-01-01T00:00Z", {
|
||||
var fromWithCases = {
|
||||
year2000: {
|
||||
year: 1378,
|
||||
eraYear: 1378,
|
||||
era: "ap",
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: 11,
|
||||
},
|
||||
year1: {
|
||||
year: -621,
|
||||
eraYear: -621,
|
||||
era: "ap",
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: 11,
|
||||
@ -120,6 +124,8 @@ var durationCases = {
|
||||
duration: { days: 280 },
|
||||
result: {
|
||||
year: 2000,
|
||||
eraYear: 2000,
|
||||
era: "ap",
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: 5,
|
||||
@ -134,6 +140,8 @@ var durationCases = {
|
||||
duration: { weeks: 40 },
|
||||
result: {
|
||||
year: 2000,
|
||||
eraYear: 2000,
|
||||
era: "ap",
|
||||
month: 10,
|
||||
monthCode: "M10",
|
||||
day: 5,
|
||||
@ -148,6 +156,8 @@ var durationCases = {
|
||||
duration: { months: 6 },
|
||||
result: {
|
||||
year: 2001,
|
||||
eraYear: 2001,
|
||||
era: "ap",
|
||||
month: 6,
|
||||
monthCode: "M06",
|
||||
day: 1,
|
||||
@ -166,6 +176,8 @@ var durationCases = {
|
||||
},
|
||||
result: {
|
||||
year: 2001,
|
||||
eraYear: 2001,
|
||||
era: "ap",
|
||||
month: 6,
|
||||
monthCode: "M06",
|
||||
day: 18,
|
||||
|
@ -15,12 +15,12 @@ esid: pending
|
||||
const tests = [
|
||||
{
|
||||
calendar: "gregory",
|
||||
era: "gregory",
|
||||
era: "ce",
|
||||
start: "0001-01-01",
|
||||
},
|
||||
{
|
||||
calendar: "gregory",
|
||||
era: "gregory-inverse",
|
||||
era: "bce",
|
||||
start: "0000-01-01",
|
||||
},
|
||||
|
||||
@ -55,29 +55,24 @@ const tests = [
|
||||
},
|
||||
{
|
||||
calendar: "japanese",
|
||||
era: "japanese",
|
||||
era: "ce",
|
||||
start: "0001-01-01",
|
||||
},
|
||||
{
|
||||
calendar: "japanese",
|
||||
era: "japanese-inverse",
|
||||
era: "bce",
|
||||
start: "0000-01-01",
|
||||
},
|
||||
|
||||
{
|
||||
calendar: "coptic",
|
||||
era: "coptic",
|
||||
era: "am",
|
||||
start: "0284-08-29",
|
||||
},
|
||||
{
|
||||
calendar: "coptic",
|
||||
era: "coptic-inverse",
|
||||
start: "0283-08-30",
|
||||
},
|
||||
|
||||
{
|
||||
calendar: "ethiopic",
|
||||
era: "ethiopic",
|
||||
era: "am",
|
||||
start: "0008-08-27",
|
||||
},
|
||||
|
||||
@ -88,7 +83,7 @@ const tests = [
|
||||
},
|
||||
{
|
||||
calendar: "roc",
|
||||
era: "roc-inverse",
|
||||
era: "broc",
|
||||
start: "1911-01-01",
|
||||
},
|
||||
];
|
||||
|
Loading…
x
Reference in New Issue
Block a user