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

The chosen best format in Intl.DateTimeFormat is potentially null #3049

Open
trflynn89 opened this issue Nov 27, 2024 · 1 comment
Open

The chosen best format in Intl.DateTimeFormat is potentially null #3049

trflynn89 opened this issue Nov 27, 2024 · 1 comment

Comments

@trflynn89
Copy link
Contributor

With the following Intl.DateTimeFormat object:

new Intl.DateTimeFormat([], { era: "narrow" });

We will enter CreateDateTimeFormat with required=ANY and defaults=DATE. And since there is no defined dateStyle or timeStyle, we hit this step to create the best format:

a. Let bestFormat be GetDateTimeFormat(formats, formatMatcher, formatOptions, required, defaults, ALL).

At this point, formatOptions will have an era field of "narrow".

When we enter GetDateTimeFormat, we will set requiredOptions to « "weekday", "year", "month", "day", "dayPeriod", "hour", "minute", "second", "fractionalSecondDigits" » because required=ANY.

We will then end up with anyPresent set to true, because formatOptions has an era field.
And we will have needDefaults set to true, because formatOptions does not have any of the fields in requiredOptions.

Thus we hit this step and return null:

17. If anyPresent is true and needDefaults is true, return null.

I don't think bestFormat is supposed to be nullable?

@trflynn89
Copy link
Contributor Author

Another case where this could happen is:

new Date().toLocaleDateString([],  { hour: "numeric" });

This invokes CreateDateTimeFormat with required=DATE and defaults=DATE.

So we have requiredOptions set to « "weekday", "year", "month", "day" », and anyPresent is true because hour is present, and needDefaults is true because the required options are all missing. Thus we return null for the best format again.

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

No branches or pull requests

1 participant