-
Notifications
You must be signed in to change notification settings - Fork 156
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
Comments
Another case where this could happen is: new Date().toLocaleDateString([], { hour: "numeric" }); This invokes So we have |
This seems like a regression from a94a793. It seems like we accidentally extended the "throw TypeError if you don't provide any relevant options to the Temporal type" behaviour described in #2795 (comment) to the existing That could be solved by only returning null from GetDateTimeFormat if However, I will tentatively say that there still seems to be a problem around |
In a94a793 the desired behaviour when formatting Temporal objects was accidentally applied to formatting Date objects. So new Date().toLocaleDateString([], { hour: "numeric" }); would result in bestFormat being null, and according to the type assertion of the Intl.DateTimeFormat [[DateTimeFormat]] internal slot, that is not possible. Checking that _inherit_ = ~relevant~ here ensures the new behaviour is only applied to Temporal objects, and the type assertion is not hit. See: #3049
I've addressed the main issue in #3053. However, after looking at this a bit more, I do think there is still a problem. The DateTimeFormat object created by
One possibility is to have special treatment for The other possibility is that it's actually a bug in ECMA-402 that CreateDateTimeFormat step 42.b makes it so that era can never occur by itself in a format. i.e., if you give My preference would be to settle the ECMA-402 bug and then 'rebase' Temporal on that. |
In a94a793 the desired behaviour when formatting Temporal objects was accidentally applied to formatting Date objects. So new Date().toLocaleDateString([], { hour: "numeric" }); would result in bestFormat being null, and according to the type assertion of the Intl.DateTimeFormat [[DateTimeFormat]] internal slot, that is not possible. Checking that _inherit_ = ~relevant~ here ensures the new behaviour is only applied to Temporal objects, and the type assertion is not hit. See: #3049
Removing |
With the following
Intl.DateTimeFormat
object:We will enter
CreateDateTimeFormat
withrequired=ANY
anddefaults=DATE
. And since there is no defineddateStyle
ortimeStyle
, we hit this step to create the best format:At this point,
formatOptions
will have anera
field of"narrow"
.When we enter
GetDateTimeFormat
, we will setrequiredOptions
to« "weekday", "year", "month", "day", "dayPeriod", "hour", "minute", "second", "fractionalSecondDigits" »
becauserequired=ANY
.We will then end up with
anyPresent
set to true, becauseformatOptions
has anera
field.And we will have
needDefaults
set to true, becauseformatOptions
does not have any of the fields inrequiredOptions
.Thus we hit this step and return null:
I don't think
bestFormat
is supposed to be nullable?The text was updated successfully, but these errors were encountered: