-
Notifications
You must be signed in to change notification settings - Fork 107
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
Normative: Add fractionalSecondDigits option #347
Conversation
v8 prototype cl https://chromium-review.googlesource.com/c/v8/v8/+/1621445 |
Thanks. This will solve my use case. |
Good point. I didn't think about that while I make the spec change but I believe we already have facility to do that. Here is one sniffing function I wrote to test in my prototype to tell it is available or not (notice, with my propose spec, you do need to add the second option too.)
Below is what I run in my prototype on v8, --harmony_intl_dateformat_millisecond_digits turn the feature on.
Run without the feature (no --harmony_intl_dateformat_millisecond_digits flag)
But this is just based on the current PR. Don't count on it until we all agree this PR is good enough. Notice in the current shape of the PR you need to pass in {second: "numeric"} as option because we won't check the "millisecondDigits" unless second is specified. I am not 100% sure that is right. Maybe that option should be read unconditionally and just got ignored if we are not formatting second? |
@littledan could you take a look again, I change the PartitionDateTimePattern to use FormatNumber. Please see does it match what you suggest or is there a better way to spec that. |
spec/datetimeformat.html
Outdated
@@ -105,6 +105,8 @@ <h1>InitializeDateTimeFormat ( _dateTimeFormat_, _locales_, _options_ )</h1> | |||
1. Let _prop_ be the name given in the Property column of the row. | |||
1. Let _value_ be ? GetOption(_options_, _prop_, `"string"`, « the strings given in the Values column of the row », *undefined*). | |||
1. Set _opt_.[[<_prop_>]] to _value_. | |||
1. If _opt_.[[Second]] is not *undefined*, 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.
@littledan , @sffc @fabalbon and everyone:
Do you think we should set opt.[[MillisecondDigits]] only if opt.[[Second]] is not undefined or it should be set unconditionally?
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 we should set opt.[[MillisecondDigits]] regardless. Like @HolgerJeromin commented, second can be set without hour. In InitializeDateTimeFormat,opt.[[Day]] will be set without opt.[[Month]].
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.
ok, I just change the PR, then the detection can be simplified as
function IsMillisecondDigitsOptionAvaiable() {
return (new Intl.DateTimeFormat()).resolvedOptions().millisecondDigits !== 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.
Off topic (?): The detection code is surprising to me. Stable Chrome returns:
(new Intl.DateTimeFormat()).resolvedOptions() // results in
{
calendar: "gregory",
day: "numeric",
locale: "en-US",
month: "numeric",
numberingSystem: "latn",
timeZone: "Europe/Berlin",
year: "numeric"
}
Why does a Chrome with your patches adds millisecondDigits
?
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.
Off topic (?): The detection code is surprising to me. Stable Chrome returns:
(new Intl.DateTimeFormat()).resolvedOptions() // results in { calendar: "gregory", day: "numeric", locale: "en-US", month: "numeric", numberingSystem: "latn", timeZone: "Europe/Berlin", year: "numeric" }Why does a Chrome with your patches adds
millisecondDigits
?
not sure your question is asking how my patch in chrome work (so I can answer you by walking you through the C++ code) or how does the spec change work (so I can answer you by walking you through the changed spec).
I did not used the
Hard to tell. Right now the following (useless?) example is working without a problem. So the current philosophy is to allow all combination. new Intl.DateTimeFormat('en-us', {
weekday: 'long',
year: 'numeric',
day: 'numeric',
second: 'numeric',
hour12: true,
timeZone: 'UTC'
}).format(Date.UTC(2012, 11, 17, 3, 0, 42)); // => "17 Monday 2012, 42" |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
As per live discussion at TC39-Berlin: I think we would be well advised to name this |
Also worth noting that we already have a (quasi-)polyfilled use case where we add |
I am going to revise this PR to change the option name to 'subsecond', should the 'type' of the formatToParts also named 'subsecond' instead of 'fractionalSecond'? |
FWIW, in our C++ code we refer to it as |
…ZoneName In this PR[1], fractionalSecondDigits is listed earlier than timeZoneName in table 6[2]. So, accessing order of fractionalSecondDigits in [3]'s step-29 should be earlier than timeZoneName. [1]: tc39/ecma402#347 [2]: https://tc39.es/ecma402/#sec-datetimeformat-abstracts [3]: https://tc39.es/ecma402/#sec-initializedatetimeformat
…ZoneName In this PR[1], fractionalSecondDigits is listed earlier than timeZoneName in table 6[2]. So, accessing order of fractionalSecondDigits in [3]'s step-29 should be earlier than timeZoneName. [1]: tc39/ecma402#347 [2]: https://tc39.es/ecma402/#sec-datetimeformat-abstracts [3]: https://tc39.es/ecma402/#sec-initializedatetimeformat
…ZoneName In this PR[1], fractionalSecondDigits is listed earlier than timeZoneName in table 6[2]. So, accessing order of fractionalSecondDigits in [3]'s step-29 should be earlier than timeZoneName. [1]: tc39/ecma402#347 [2]: https://tc39.es/ecma402/#sec-datetimeformat-abstracts [3]: https://tc39.es/ecma402/#sec-initializedatetimeformat
Hi! I was digging around for ways to format a date, and stumbled on DateTimeFormat. Kind of amazing to realize this only been out a few weeks/months (StackOverflow hasn't noticed it at all yet!), and I'm already able to leverage it. :) Given thread recency/activity, existing mentions of implementation behavior, and the obvious benefits of skipping the triage lag at bugs.chromium.org... The following "works" (without behaving as intended) in Chromium 83, and fails in Chrome 85.
Chrome 83: "Sep 13, 2020, 4:11 PM" Chrome 85:
It appears that this is because Chrome ~85 has just landed actual support for fractional seconds, and the code now does the relevant bounds checking. The error message is somewhat confusing though. As side meta-discussion, I'm curious how I'd achieve "Sep 13, 2020, 4:11.267 PM". It appears not currently possible to do this by just using |
The exception in Chrome 85 is due to a spec change in dateStyle/timeStyle, which were still draft at the time (they've since become stable). See https://bugs.chromium.org/p/chromium/issues/detail?id=1124778. This spec change was done in part to avoid the surprising behavior you noted. In order to get your desired format, you just need to avoid using dateStyle/timeStyle. new Intl.DateTimeFormat('en', {
year: "numeric",
month: "short",
day: "numeric",
hour: "numeric",
minute: "2-digit",
second: "2-digit",
fractionalSecondDigits: 2,
}).format(); |
Agree. And that is fixed in chrome on "Fri, Sep 11, 2020, 4:28 AM PDT" in The new error message you will see in Chrome 87 is
|
What is blocking this PR to be merged? |
@FrankYFTang yesterday I did some review work on pending PRs and jumped those with the needs tests labels. Please let me take a look again here. |
I'm afraid we never recorded consensus in this PR thread, please correct me if I'm wrong. I'll go through the meeting notes and confirm. |
Consensus is recorded in the wiki with a link to the notes from 2019-07-11: |
Yes, the notes helped me a lot and, as I said, I quickly jumped over this PR due to the existing labels. |
1. Else if _p_ matches a Property column of the row in <emu-xref href="#table-datetimeformat-components"></emu-xref>, then | ||
1. Let _f_ be the value of _dateTimeFormat_'s internal slot whose name is the Internal Slot column of the matching row. |
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.
The removal of this line (line 336) is a mistake during editing. Please add it back @leobalter Totally my fault.
Address #300 @HolgerJeromin
UPDATED 6/5/2019 1300 PST
Format Millisecond