Skip to content

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

Open
@trflynn89

Description

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?

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions