Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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

Normative: Don't add default formatting to lone era #957

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ptomato
Copy link
Contributor

@ptomato ptomato commented Feb 6, 2025

Previously, if era was given by itself in the formatting options, the default formatting for the other date/time components would be added. This is inconsistent with what we do for dayPeriod where a lone dayPeriod produces formats such as "in the afternoon".

The use case of obtaining the localized era name has also been mentioned several times.

This change makes a lone era be passed to the format matcher algorithm without added date/time components, and requires implementations to have at least a year-month-day-era and year-month-era format available (which looks to be widely available across languages in CLDR.)

See: #461

@ptomato ptomato requested a review from sffc February 6, 2025 17:39
@anba
Copy link
Contributor

anba commented Feb 6, 2025

Does this require any changes in https://tc39.es/ecma402/#sec-intl.datetimeformat-internal-slots? Right now neither era nor timeZoneName are required to be present in the minimum available formats. That means for example when requesting {era: "long"}, it's valid for BasicFormatMatcher to return the format for "hour, minute" (assuming only the minimum required formats are present in the implementation.)

When given the request {era: "long"}, BasicFormatMatcher will compute the best score for:

  • year, month
  • month, day
  • hour, minute
  • dayPeriod, hour

There's a removal penalty because era is not present, and twice an addition penalty, because other fields are present. So the best score is -120 - 2*20 = -160. The formats list is unordered, so any of these four formats can be returned.

@ptomato
Copy link
Contributor Author

ptomato commented Feb 6, 2025

I assumed no, because we also permit dayPeriod by itself but dayPeriod by itself is not part of the minimum required formats. (Although, maybe this is slightly different because dayPeriod is present with other fields.)

@anba
Copy link
Contributor

anba commented Feb 6, 2025

(Although, maybe this is slightly different because dayPeriod is present with other fields.)

Yes, this is the important difference. Standalone dayPeriod is not required to be an available format, but at least it's guaranteed that a format is returned which includes dayPeriod when requesting standalone dayPeriod. Standalone era or standalone timeZoneName can return formats which contain neither era nor timeZoneName.

spec/datetimeformat.html Outdated Show resolved Hide resolved
@ptomato
Copy link
Contributor Author

ptomato commented Feb 7, 2025

Conclusion in the TG2 meeting today was:

  • This should be split up into two PRs and era added separately from timeZoneName
  • In both cases research should be done to check if it is likely to be web compatible
  • If not web compatible, consider other options like { era: 'long', standalone: true }

Previously, if `era` was given by itself in the formatting options, the
default formatting for the other date/time components would be added.
This is inconsistent with what we do for `dayPeriod` where a lone
`dayPeriod` produces formats such as "in the afternoon".

The use case of obtaining the localized era name has also been mentioned
several times.

This change makes a lone `era` be passed to the format matcher algorithm
without added date/time components, and requires implementations to have
at least a year-month-day-era and year-month-era format available (which
looks to be widely available across languages in CLDR.)

See: tc39#461
@ptomato ptomato force-pushed the 461-era-timeZoneName-alone branch from 28755d0 to 33a7366 Compare February 7, 2025 00:36
@ptomato ptomato changed the title Normative: Don't add default formatting to lone era or timeZoneName Normative: Don't add default formatting to lone era Feb 7, 2025
@ptomato
Copy link
Contributor Author

ptomato commented Feb 7, 2025

I've updated this to modify only era. I will open a separate PR for timeZoneName.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Previously Discussed
Development

Successfully merging this pull request may close these issues.

2 participants