Skip to content
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

Editorial: Align non-ISO calendar validation with ISO behaviour #2940

Merged

Conversation

gibson042
Copy link
Collaborator

@gibson042 gibson042 commented Sep 16, 2024

Fixes #2863
Fixes #2864
Fixes #2866

Updated recommendations for non-ISO calendars:

  • Never ignore a specified year in CalendarMonthDayToISOReferenceDate.
  • Require year information to accompany month index (and enforce that in the polyfill).
  • Enforce consistency of era + eraYear vs. year and (where relevant) monthCode vs. month.

test262 PR: tc39/test262#4231

Help wanted with further testing and thorough verification of correctness and coverage.

@gibson042 gibson042 changed the title Polyfill: Enforce consistency of era + eraYear vs. year and (where relevant) monthCode vs. month in non-ISO calendars Normative: Enforce consistency of era + eraYear vs. year and (where relevant) monthCode vs. month in non-ISO calendars Sep 16, 2024
@gibson042 gibson042 changed the title Normative: Enforce consistency of era + eraYear vs. year and (where relevant) monthCode vs. month in non-ISO calendars Normative: Align non-ISO calendar validation with ISO behaviour Sep 17, 2024
@gibson042 gibson042 force-pushed the gh-2864-universal-year-and-month-consistency branch from cd68da4 to fa3c85e Compare September 18, 2024 22:01
spec/calendar.html Outdated Show resolved Hide resolved
polyfill/lib/calendar.mjs Outdated Show resolved Hide resolved
spec/calendar.html Show resolved Hide resolved
@gibson042 gibson042 force-pushed the gh-2864-universal-year-and-month-consistency branch 2 times, most recently from 0b67f86 to ff30462 Compare September 19, 2024 15:58
@gibson042 gibson042 changed the title Normative: Align non-ISO calendar validation with ISO behaviour Editorial: Align non-ISO calendar validation with ISO behaviour Sep 19, 2024
Comment on lines -1400 to +1403
const checkField = (name, value) => {
const checkField = (name, value, aliases) => {
const currentValue = calendarDate[name];
if (currentValue != null && currentValue != value) {
if (
currentValue != null &&
currentValue != value &&
!ES.Call(ArrayPrototypeIncludes, aliases || [], [currentValue])
) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change (and the corresponding adaptation to return eraAliases below) could use some more attention in tests. I believe it's correct and necessary, but there aren't any tests that fail if I revert it. I propose that we still go ahead and merge this but if you have an idea for a test case, please add it to test262 in a follow up.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, let's see... without this use of aliases, a call like Temporal.PlainDate.from({ calendar: "gregory", era: "ce", eraYear: 2024, year: 2000, month: 1, day: 1 }) (having year along with era and eraYear) fails with RangeError "Input era ce doesn't match calculated value gregory". So there's your test case input, although I'm not sure where to put it in test262 so can I ask you to do that and I'll review?

Also, I feel like the polyfill has terrible choices for the primary names of Gregorian calendar eras—the above should probably read like "…doesn't match calculated value ce" or "…doesn't match calculated value ad", and the message for Temporal.PlainDate.from({ calendar: "gregory", era: "ce", eraYear: 0, year: 0, month: 1, day: 1 }) should probably be "Input era ce doesn't match calculated value bce" or "Input era ce doesn't match calculated value bc" rather than "Input era ce doesn't match calculated value gregory-inverse" because what the heck is "gregory-inverse" to the median developer?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the test case. This is done in tc39/test262#4232. I checked that it fails when you revert the aliases fix.

Re. the era names, our hands are tied, as I'm trying to follow the current state of the Intl Era and Month Codes proposal. Justin has a ticket open for improving the canonical names. I guess in the polyfill we could prefer printing an alias in the error messages if there is one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks; test262 PR approved.

And I just now left a comment on the era/month code issue; we're right to keep the polyfill aligned with it but hopefully that part will improve.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could show both the month code proposal names and the more recognizable alias(es) in the error message?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tentatively, that's what we're doing now since #2944. If the era/monthcode proposal changes, we can change it to do something else.

Copy link
Collaborator

@ptomato ptomato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, I have merged the test262 tests and I will update this branch to pull them in.

@ptomato ptomato merged commit d932d5a into tc39:main Sep 19, 2024
6 checks passed
ptomato added a commit to ptomato/test262 that referenced this pull request Sep 20, 2024
There was a coverage gap for converting calendar fields to a date when the
provided era was an alias.

See tc39/proposal-temporal#2940 (comment)
Ms2ger pushed a commit to ptomato/test262 that referenced this pull request Sep 20, 2024
There was a coverage gap for converting calendar fields to a date when the
provided era was an alias.

See tc39/proposal-temporal#2940 (comment)
Ms2ger pushed a commit to tc39/test262 that referenced this pull request Sep 20, 2024
There was a coverage gap for converting calendar fields to a date when the
provided era was an alias.

See tc39/proposal-temporal#2940 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants