-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Polyfill: Update per #2500 #2663
Conversation
0669f4b
to
02bd585
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #2663 +/- ##
==========================================
+ Coverage 96.30% 96.35% +0.05%
==========================================
Files 20 20
Lines 12204 12196 -8
Branches 2276 2274 -2
==========================================
- Hits 11753 11752 -1
+ Misses 393 389 -4
+ Partials 58 55 -3
☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK to merge when the review comments on the tests are addressed. Thanks for following up!
My naive memory of this (happy to be corrected) was that the deviations here were intentional, because we wanted the shape of arguments (not their values) to determine the exceptions thrown.
@sffc - do you remember our decisions here, and does the above represent those decisions correctly? |
I believe what @justingrant said is correct. The behavior should be: // Success: numeric month and day explicitly in an options bag means ISO-8601
Temporal.PlainMonthDay.from({ month: 8, day: 22 })
// Reject: calendar with numeric month and day (no data-driven exception)
Temporal.PlainMonthDay.from({ month: 8, day: 22, calendar: "iso8601" })
Temporal.PlainMonthDay.from({ month: 8, day: 22, calendar: "buddhist" })
// Success: monthCode, day, and calendar all explicit
Temporal.PlainMonthDay.from({ monthCode: "M08", day: 22 })
Temporal.PlainMonthDay.from({ monthCode: "M08", day: 22, calendar: "iso8601" })
Temporal.PlainMonthDay.from({ monthCode: "M08", day: 22, calendar: "buddhist" }) This behavior is what is currently in the polyfill. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that this is a change we want to make. See #2663 (comment)
The current state of the polyfill is inconsistent with both the pre-#2500 spec and the post-#2500 spec, so that definitely needs updating. As for the spec, it is content to accept month without year or monthCode for the ISO 8601 calendar whether implicit (e.g., But on that point, the previous "only shape matters" state was inconsistent—not just in the trivial sense of e.g. "M13" being an acceptable monthCode in some calendars but not others, but more relevantly because whether a month without year or monthCode is acceptable is data-dependent in both string form (e.g., "08-23[u-ca=iso8601]" is accepted but "08-23[u-ca=gregory]" is not) and more importantly in object form (e.g., even pre-#2500, So if we truly want a normative change that restores rejection of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thanks so much for your patience while we collectively figured out the right behavior here.
I assume tests are coming? Also needs a rebase and autosquash. |
5967ef9
to
8a8f7d1
Compare
Related test262 PR: tc39/test262#3899
Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to go, when the tests are.
<li>If _type_ is ~date~ or ~year-month~ and the calendar supports the usual partitioning of years into eras with their own year counting as represented by *"year"*, *"era"*, and *"eraYear"* (as in the Gregorian or traditional Japanese calendars) and any of the following cases apply:<ul> | ||
<li>The value for each of *"year"* and *"era"* and *"eraYear"* is *undefined*.</li> | ||
<li>The value for *"era"* is *undefined* but the value for *"eraYear"* is not.</li> | ||
<li>The value for *"eraYear"* is *undefined* but the value for *"era"* is not.</li> | ||
<li>None of the three values are *undefined* but the values for *"era"* and *"eraYear"* do not together identify the same year as the value for *"year"*.</li> | ||
</ul></li> | ||
</ul> | ||
<emu-note> | ||
When _type_ is ~month-day~ and *"month"* is provided without *"monthCode"*, it is recommended that all built-in calendars other than the ISO 8601 calendar require a disambiguating year (e.g., either *"year"* or *"era"* and *"eraYear"*), including those that always use exactly the same months as the ISO 8601 calendar (which receives special handling in this specification as a default calendar that is permanently stable for automated processing). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't know if we want this, but maybe:
When _type_ is ~month-day~ and *"month"* is provided without *"monthCode"*, it is recommended that all built-in calendars other than the ISO 8601 calendar require a disambiguating year (e.g., either *"year"* or *"era"* and *"eraYear"*), including those that always use exactly the same months as the ISO 8601 calendar (which receives special handling in this specification as a default calendar that is permanently stable for automated processing). | |
When _type_ is ~month-day~ and *"month"* is provided without *"monthCode"*, all built-in calendars other than the ISO 8601 calendar must require a disambiguating year (e.g., either *"year"* or *"era"* and *"eraYear"*), including those that always use exactly the same months as the ISO 8601 calendar (which receives special handling in this specification as a default calendar that is permanently stable for automated processing). |
(in order to make it clear that there should not be implementation divergence)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I definitely don't want to introduce such a strong statement in this PR, and I'm not sure it belongs in the text at all (it's true that built-in calendars are constrained to CLDR, but that source itself can change over time). Even CalendarDateMonthCode, which I consider to be much more strict regarding "M##[L]" formatting, uses "should" rather than "must".
8a8f7d1
to
23df8ff
Compare
While working on the tests I found an additional misalignment between the polyfill and the spec. CalendarResolveFields says "The operation throws a TypeError exception if the properties of fields are internally inconsistent within the calendar or insufficient to identify a unique instance of type in the calendar." But the polyfill would throw Normally I'd open a separate PR to correct this, but since it also requires updating the test262 tests which were incorrect, that would cause another sync-and-rebase dance. So for convenience I've just appended the fix to this PR. |
From CalendarResolveFields: "The operation throws a *TypeError* exception if the properties of _fields_ are internally inconsistent within the calendar or insufficient to identify a unique instance of _type_ in the calendar."
23df8ff
to
a58a0f4
Compare
This PR removes some dead steps from PlainMonthDay-related spec algorithms to hopefully clarify that year is optional only for the ISO 8601 calendar—and that in that calendar it is always optional (regardless of entry point or presence vs. absence of
month
and/ormonthCode
)—and then updates the polyfill accordingly, fixing a gap from #2500 that supportedTemporal.PlainMonthDay.from({ monthCode, day })
andTemporal.PlainMonthDay.from({ month, day })
but notTemporal.PlainMonthDay.from({ month, day, calendar: "iso8601" })
orTemporal.Calendar.from("iso8601").monthDayFromFields({ month, day })
).Note that polyfilled non–ISO-8601 calendars, including "gregory", continue to reject input that fails to include at least one of
year
andmonthCode
.Related test262 PR: tc39/test262#3899
Fixes #2664