tc39 / proposal-temporal

Provides standard objects and functions for working with dates and times.
https://tc39.es/proposal-temporal/docs/
Other
3.32k stars 150 forks source link

CalendarMonthDayToISOReferenceDate: Throw RangeError if resolved date is outside of valid limits #2997

Closed anba closed 2 weeks ago

anba commented 2 weeks ago

CalendarMonthDayToISOReferenceDate should have the same note as in CalendarDateToISO to disallow dates outside the valid limits:

It also throws a RangeError exception if the date described by fields is outside the range allowed by ISODateWithinLimits.

Reason: The resolved year can be far into the past and may be outside the valid limits.

The maximum year for ICU4X is -5738:

js> Temporal.PlainMonthDay.from({day: 30, monthCode: "M09L", calendar: "chinese"}, {overflow: "reject"}).toString();
"-005738-11-17[u-ca=chinese]"

ICU4C computes dates possibly even further into the past. -239723 is computed as the first year where M09L-30 exists:

js> new Intl.DateTimeFormat("en-u-ca-chinese", {timeZone:"UTC"}).format(new Date("-239723-01-05")) 
"9bis/30/-239723"

ICU4C doesn't compute any 30 days months for M01L, M10L, M11L, and M12L inside the Date limits. But it's possible that ICU4C can compute 30 days leap months outside those limits.

ptomato commented 2 weeks ago

Given #2869 I am skeptical about the accuracy of these dates, but this is a good point. It's possible that we trip an assertion here, so we should add this. Note that as of #2996, this is no longer a note in CalendarDateToISO, but an actual step in CalendarDateFromFields/CalendarYearMonthFromFields. So I'll add a similar step in CalendarMonthDayFromFields.

ptomato commented 2 weeks ago

(I'm hesitant to add a test262 test for this, though, since it may be based on spurious data.)