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

AdjustDateTimeStyleFormat: Don't adjust format when no conflicting options are present? #3062

Open
anba opened this issue Dec 11, 2024 · 2 comments

Comments

@anba
Copy link
Contributor

anba commented Dec 11, 2024

AdjustDateTimeStyleFormat determines a new format even when no conflicting options are present. This leads to the following results:

js> console.log(new Date(0).toLocaleString("ja", {dateStyle: "full"}))                                                                           
1970年1月1日木曜日
js> console.log(new Temporal.PlainDate(1970, 1, 1).toLocaleString("ja", {dateStyle: "full"})) 
1970/1/1木曜日

The polyfill already appears to use the original format, because it returns:

> console.log(new Temporal.PlainDate(1970, 1, 1).toLocaleString("ja", {dateStyle: "full"}))
1970年1月1日木曜日
@ptomato
Copy link
Collaborator

ptomato commented Feb 15, 2025

Hmm, this shouldn't be happening according to my reading of the spec — do you know what's the difference between the two formats in the above code example? Is there something extra that should be in allowedOptions but isn't?

@anba
Copy link
Contributor Author

anba commented Feb 17, 2025

AdjustDateTimeStyleFormat calls either BasicFormatMatcher or BestFitFormatMatcher, which compute the format using the data in %Intl.DateTimeFormat%.[[LocaleData]].[[<locale>]].[[formats]]. Whereas DateTimeStyleFormat uses the format data from %Intl.DateTimeFormat%.[[LocaleData]].[[<locale>]].[[styles]]. This distinction is based on how CLDR structures the data (<dateFormats> and <timeFormats> for the [[styles]] record and <availableFormats> for the [[formats]] record.)

Because there are two different data sources ([[styles]] and [[formats]]), calling AdjustDateTimeStyleFormat with a format record from DateTimeStyleFormat can lead to different outputs, as shown in the example.


There's a <datetimeSkeleton> element in CLDR to map styles to available formats, so we could change ECMA-402 to define [[styles]] in terms of the formats in [[formats]]. That way it's guaranteed that every format from DateTimeStyleFormat can also be returned from {Basic,BestFit}FormatMatcher, which ensures we get consistent formatting. Unfortunately ICU4C doesn't yet support returning <datetimeSkeleton> and CLDR data also needs some fixing first, see https://unicode-org.atlassian.net/browse/CLDR-14993.

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

No branches or pull requests

2 participants