-
Notifications
You must be signed in to change notification settings - Fork 106
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
Support hc extension key in DateTimeFormat. #135
Conversation
@caridy - r? |
will take a look at is next week. also remember that we want to document this process for future similar enhancements. |
@caridy - ping? |
@@ -592,7 +600,7 @@ | |||
</p> | |||
|
|||
<p> | |||
The function returns a new object whose properties and attributes are set as if constructed by an object literal assigning to each of the following properties the value of the corresponding internal slot of this DateTimeFormat object (see <emu-xref href="#sec-properties-of-intl-datetimeformat-instances"></emu-xref>): locale, calendar, numberingSystem, timeZone, hour12, weekday, era, year, month, day, hour, minute, second, and timeZoneName. Properties whose corresponding internal slots have the value *undefined* are not assigned. | |||
The function returns a new object whose properties and attributes are set as if constructed by an object literal assigning to each of the following properties the value of the corresponding internal slot of this DateTimeFormat object (see <emu-xref href="#sec-properties-of-intl-datetimeformat-instances"></emu-xref>): locale, calendar, numberingSystem, timeZone, hourCycle, weekday, era, year, month, day, hour, minute, second, and timeZoneName. Properties whose corresponding internal slots have the value *undefined* are not assigned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add support here for emulating the old hour12 field in resolvedOptions when hourCycle is one of the forms supported by it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what are you asking here @littledan, can you clarify?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If anyone is using the hour12
field of the resolvedOptions(), this patch makes it go away. That risks web compatibility. For that reason, I'd rather we not merge this patch.
One way to resolve this would be to hold around the hour12
option that the users passed in, and then just pass that back out. I'd suggest, on the other hand, to just use the [[HourCycle]] internal slot that we already have: if the hourCycle is one of the two values that hour12 would provide, then use that in an hour12
property; otherwise, omit the hour12
property.
In my opinion, it's OK to have hour12
in the output even if it wasn't in the input. This is just another instance of the pattern where resolvedOptions
has options that the user didn't provide, but were chosen by, e.g., locale selection or matching a pattern.
I've made this suggestion a couple times in the past; I must not have been explaining myself clearly. I'll follow up with spec text to explain the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you're absolutely right! I didn't think of this before. And yes, I agree with always providing the value of hour12
as part of the resolvedOptions. As part of the documentation of the process for this kind of changes, I will document this as well. @zbraniecki can you update the PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make sure this does not risk web compatibility before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hour12
option to always surface as part of the resolvedOptions for web-compat.
Updated. @caridy and @littledan - can you re-review please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's enough for now, but let's wait for @littledan to look at it since he was the one noticing this.
spec/datetimeformat.html
Outdated
</p> | ||
|
||
<p> | ||
For web compatibility reasons, if the property hourCycle is set to values *h12* or *h24*, the corresponding property hour12 should be set as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works, but I'm not a huge fan of this wording for a couple minor reasons:
- Seems like, suddenly,
hourCycle
comes last in the enumeration order of the resolvedOptions object. This is extremely minor, but it's a rather unmotivated (only by spec wording constraints) observable effect of the change. - Comments like "for web compatibility reasons" belong in notes, rather than normative text (otherwise it looks a little bit like an "Annex B" normative-optional thing). There are tons and tons of things in all kinds of specs are for web compatibility reasons; probably better to just say what the behavior is.
It would be best to reword the resolvedOptions methods in a more imperative way, as suggested in #124 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spec/datetimeformat.html
Outdated
1. If _hr12_ is *undefined*, then | ||
1. Let _hr12_ be Get(_dataLocaleData_, *"hour12"*). | ||
1. Set _dateTimeFormat_.[[Hour12]] to _hr12_. | ||
1. Let _hc_ be ? GetOption(_options_, *"hourCycle"*, *"string"*, « *"h12"*, *"h24"* », *undefined*). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should h11 and h23 be in this list as well? (I thought that was the whole point of the feature.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, h11 and h23 can be added later to hourCycle
. For now, we do not support them, and I'd prefer to add new features (like support for other hc options) in a separate proposal leaving this just to migrating the option name from a binary, to multioption.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to add hourCycle together with the other possible values. What's the reason to wait? Is the main motivation for this feature to have the hc
BCP 47 option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason to wait?
Supporting more options requires algorithm changes around hour token formatting.
Ok, I'll work on that, but this will increase the size of this patch substantially and require a re-review.
spec/datetimeformat.html
Outdated
@@ -278,7 +283,7 @@ | |||
1. Let _v_ be the value of _tm_'s field whose name is the Internal Slot column of the matching row. | |||
1. If _p_ is *"year"* and _v_ ≤ 0, let _v_ be 1 - _v_. | |||
1. If _p_ is *"month"*, increase _v_ by 1. | |||
1. If _p_ is *"hour"* and _dateTimeFormat_.[[Hour12]] is *true*, then | |||
1. If _p_ is *"hour"* and _dateTimeFormat_.[[HourCycle]] is *true*, then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than true, do you want to compare it to h11 and h12?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since I don't want to add other hour cycle formats yet, I'll just switch it to 'h12'.
@littledan - switched the patch to cover |
Oh, I had forgotten about Just for completeness, another option for the API surface would be to, instead, reinforce LGTM for this, but if @caridy, @jungshik or @srl295 could weigh in on this API vs that potential one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was confused about hourNo0
--it was simply part of the data model. And now, that instead comes from the "hourCycle" field on dataLocaleData if not provided by the user--makes sense to me.
Overall, this patch seems great to me; sorry for my trouble in understanding it.
spec/datetimeformat.html
Outdated
@@ -622,8 +640,7 @@ | |||
<li>[[NumberingSystem]] is a String value with the "type" given in Unicode Technical Standard 35 for the numbering system used for formatting.</li> | |||
<li>[[TimeZone]] is a String value with the IANA time zone name of the time zone used for formatting.</li> | |||
<li>[[Weekday]], [[Era]], [[Year]], [[Month]], [[Day]], [[Hour]], [[Minute]], [[Second]], [[TimeZoneName]] are each either *undefined*, indicating that the component is not used for formatting, or one of the String values given in <emu-xref href="#table-datetimeformat-components"></emu-xref>, indicating how the component should be presented in the formatted output.</li> | |||
<li>[[Hour12]] is a Boolean value indicating whether 12-hour format (*true*) or 24-hour format (*false*) should be used. It is only used when [[Hour]] is not *undefined*.</li> | |||
<li>[[HourNo0]] is a Boolean value indicating whether hours from 1 to 12 (*true*) or from 0 to 11 (*false*) should be used. It is only used when [[Hour12]] has the value *true*.</li> | |||
<li>[[HourCycle]] is a String value indicating whether 12-hour format (*"h11"*, *"h12"*) or 24-hour format (*"h23"*, *"h24"*) should be used. It is only used when [[Hour]] is not *undefined*.</li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this description explain the difference between the 11/23 and 12/24 values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good fix, seems ready to land.
I think it's all ready to land then :) |
@zbraniecki can you help with the tests needed for this? |
Sorry that I didn't state this earlier, but I think that in addition to the patch looking good, it's nice if we have a couple things in place before actually merging:
I guess it's already merged, but if we could keep these requirements in mind for future normative changes, it'd be nice. |
I'm working on the implementation for SpiderMonkey in bug https://bugzilla.mozilla.org/show_bug.cgi?id=1386146 and will add test262 tests as well in the process. |
That's the first step to fix #105