Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions polyfill/lib/calendar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,16 @@ function simpleDateDiff(one, two) {
};
}

function clampISODate(iso) {
if (iso.year < -271821 || (iso.year === -271821 && (iso.month < 4 || (iso.month === 4 && iso.day < 19)))) {
return { year: -271821, month: 4, day: 19 };
}
if (iso.year > 275760 || (iso.year === 275760 && (iso.month > 9 || (iso.month === 9 && iso.day > 13)))) {
return { year: 275760, month: 9, day: 13 };
}
return iso;
}

/**
* Implementation that's common to all non-trivial non-ISO calendars
*/
Expand Down Expand Up @@ -877,7 +887,7 @@ const nonIsoHelperBase = {
}

// First, try to roughly guess the result
let isoEstimate = this.estimateIsoDate({ year, month, day });
let isoEstimate = clampISODate(this.estimateIsoDate({ year, month, day }));
const calculateSameMonthResult = (diffDays) => {
// If the estimate is in the same year & month as the target, then we can
// calculate the result exactly and short-circuit any additional logic.
Expand Down Expand Up @@ -909,7 +919,7 @@ const nonIsoHelperBase = {
let diff = simpleDateDiff(date, roundtripEstimate);
if (diff.years !== 0 || diff.months !== 0 || diff.days !== 0) {
const diffTotalDaysEstimate = diff.years * 365 + diff.months * 30 + diff.days;
isoEstimate = addDaysISO(isoEstimate, diffTotalDaysEstimate);
isoEstimate = clampISODate(addDaysISO(isoEstimate, diffTotalDaysEstimate));
roundtripEstimate = this.isoToCalendarDate(isoEstimate, cache);
diff = simpleDateDiff(date, roundtripEstimate);
if (diff.years === 0 && diff.months === 0) {
Expand Down Expand Up @@ -1871,7 +1881,7 @@ const helperJapanese = ObjectAssign(
{ code: 'heisei', isoEpoch: { year: 1989, month: 1, day: 8 }, anchorEpoch: { year: 1989, month: 1, day: 8 } },
{ code: 'showa', isoEpoch: { year: 1926, month: 12, day: 25 }, anchorEpoch: { year: 1926, month: 12, day: 25 } },
{ code: 'taisho', isoEpoch: { year: 1912, month: 7, day: 30 }, anchorEpoch: { year: 1912, month: 7, day: 30 } },
{ code: 'meiji', isoEpoch: { year: 1868, month: 9, day: 8 }, anchorEpoch: { year: 1868, month: 9, day: 8 } },
{ code: 'meiji', isoEpoch: { year: 1868, month: 10, day: 23 }, anchorEpoch: { year: 1868, month: 10, day: 23 } },
{ code: 'ce', isoEpoch: { year: 1, month: 1, day: 1 } },
{ code: 'bce', reverseOf: 'ce' }
]),
Expand Down
1 change: 1 addition & 0 deletions polyfill/lib/intl.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ function monthDayAmend(originalOptions) {
full: { month: 'long', day: 'numeric' }
};
const options = amend(originalOptions, {
era: false,
year: false,
hour: false,
minute: false,
Expand Down
24 changes: 19 additions & 5 deletions polyfill/test/expected-failures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle-default.js

# Possibly faulty calculations for year 0 in Hebrew calendar in ICU4C
# https://unicode-org.atlassian.net/browse/ICU-23007
staging/sm/Temporal/PlainDate/from-constrain-hebrew.js

# Test is incorrect, no reason why this date should not exist; seems to be
# working around an ICU4X bug
staging/sm/Temporal/PlainDate/from-islamic-umalqura.js
intl402/Temporal/PlainDate/from/calc-epoch-year-hebrew.js

# Faulty leap month calculations in Chinese calendar in ICU4C
# https://unicode-org.atlassian.net/browse/ICU-13195
intl402/Temporal/PlainDate/prototype/monthCode/chinese-calendar-dates.js
intl402/Temporal/PlainDateTime/prototype/monthCode/chinese-calendar-dates.js
intl402/Temporal/PlainMonthDay/prototype/monthCode/chinese-calendar-dates.js
Expand All @@ -34,3 +31,20 @@ staging/sm/Temporal/PlainMonthDay/from-chinese-leap-month-uncommon.js
# Fails on V8, no upstream bug open yet
intl402/DateTimeFormat/prototype/resolvedOptions/resolved-calendar-unicode-extensions-and-options.js
intl402/DateTimeFormat/prototype/resolvedOptions/resolved-numbering-system-unicode-extensions-and-options.js

# ICU4C internal error in extreme dates in chinese/dangi calendars
intl402/Temporal/PlainDate/from/extreme-dates.js
intl402/Temporal/PlainDateTime/from/extreme-dates.js
intl402/Temporal/PlainYearMonth/from/extreme-dates.js
intl402/Temporal/ZonedDateTime/from/extreme-dates.js

# ICU4C 77 failures. Remove these lines when updating to a version of Node.js
# with ICU4C 78.
intl402/Temporal/PlainDate/from/hebrew-keviah.js
intl402/Temporal/PlainDate/from/roundtrip-from-string.js
intl402/Temporal/PlainDate/prototype/daysInYear/basic-hebrew.js
intl402/Temporal/PlainDateTime/from/roundtrip-from-string.js
intl402/Temporal/PlainDateTime/prototype/daysInYear/basic-hebrew.js
intl402/Temporal/PlainYearMonth/prototype/daysInYear/basic-hebrew.js
intl402/Temporal/ZonedDateTime/from/roundtrip-from-string.js
intl402/Temporal/ZonedDateTime/prototype/daysInYear/basic-hebrew.js
2 changes: 1 addition & 1 deletion polyfill/test262
Submodule test262 updated 1052 files