-
Notifications
You must be signed in to change notification settings - Fork 9
Date-time field widths not set for PartitionDateTimePattern #45
Comments
@anba, I'm confused about your point:
The spec has:
In 1.4.1 we use I'm confused about your report, can you clarify? |
Sure. Let's take Pattern strings in ECMA-402 don't include any field widths, so when the string And because So we need to fix InitializeDateTimeFormat to set the field widths when DateTimeStylePattern is used. And instead of simply storing
DateTimeStylePattern must then be modified to return a record, possibly by combining two records when date- and time-style parts are present. The record returned from DateTimeStylePattern must then be applied to the All this will ensure PartitionDateTimePattern can properly format the pattern string. Furthermore, we will then need to adjust The overall record structure will need to be something like:
We can't use:
because CLDR/ICU may give different field widths for different hour-cycles. For example, (Edit: See the next comment for why this may actually be okay to do for now.) |
Hmm, this actually already a problem in the main ECMA-402 spec when compared to what's implemented in engines: js> new Date("2020-01-01T01:02:03").toLocaleString("en-u-hc-h12")
"1/1/2020, 1:02:03 AM"
js> new Date("2020-01-01T01:02:03").toLocaleString("en-u-hc-h23")
"1/1/2020, 01:02:03" Per spec it is illegal to format
|
Ahh! Thank you! This is an excellent introspection into the issue, and very actionable for me!
Am I correct that we should file it against ecma402? |
I started #48 to address this, and first focused on the I have some questions about the other two:
I'm not sure how to rewrite the paragraph we're adding with this patch to match what you're asking about. We do have Table 2 fields in it already, right? What's missing then?
I'm not sure if this is the right thing to do. let dtf = new Intl.DateTimeFormat(undefined, {
dateStyle: "long"
});
// Option 1
dtf.resolvedOptions(); // {dateStyle: "long"}
// Option 2
dtd.resolvedOptions(); // {dateStyle: "long", "year": "numeric", month: "long", "day: "numeric"} Are we sure we want the former, and not he latter? |
It might be nice to have the fields be returned in resolvedOptions, rather than undefined. I find it a bit surprising that we currently return only dateStyle but not the fields to which the dateStyle resolved. I don't have a great sense of the consequences of this decision, though. |
One consequence is that the resolved options can no longer be used to copy an |
Instead of:
We need something like:
|
Yes, I think that makes sense. We have to ask ourselves if it makes sense to allow that the hour-cycle option affects the pattern selection algorithm. From what I can tell, this only affects the "hour", "minute", and "second" fields. Theoretically ICU supports the |
We have some properties in Intl that get remapped; for example, One other approach here could be to not return dateStyle at all, and only return the fields. But, that might not roundtrip completely, due to the formatRange bug. However, hopefully that bug will be fixed soon on the CLDR side. |
I spun off #49 and tc39/ecma402#454 so that the current scope of this issue remains just what's in #48. Hope that works for everyone. |
Sounds good. Keep this issue for the editorial stuff. |
DateTimeStylePattern
only returns a pattern string, let's say fordateStyle
the string"{day}.{month}.{year}"
. When this pattern string is processed in 13.1.6 PartitionDateTimePattern:We hit a problem, because the internal slots were never set in
InitializeDateTimeFormat
, so they still default toundefined
.Three things to fix:
InitializeDateTimeFormat
.Intl.DateTimeFormat.prototype.resolvedOptions
to not output these fields whendateStyle
ortimeStyle
is present.The text was updated successfully, but these errors were encountered: