-
Notifications
You must be signed in to change notification settings - Fork 9
Idea about combining dateStyle/timeStyle with other options #40
Comments
https://unicode-org.atlassian.net/browse/ICU-13518 makes round-tripping error-prone, because the wrong skeleton may be returned for a given pattern. |
I also posted some thoughts in #2; my fault for double-threading. Let's keep conversation here. I said:
@zbraniecki replied:
|
To summarize my thoughts: because a programmer may reasonably expect the combination of dateStyle/timeStyle with other options to have sensible behavior, and because it's not clear what that behavior should be, we should consider throwing RangeError when the options are combined. This gives us more time to think about what we want the behavior to be. Throwing a RangeError in this situation would be a normative change, and would roll back what we had previously discussed in #2. |
I wrote a PR that does not make an exception for
|
SGTM |
I updated the PR to allow for |
Test need to be changed in test262 tc39/test262#2659 |
Also, are there tests to ensure the TypeError do got throw when this happen in test262? |
For posterity, I’ve received numerous reports of Chrome with this change breaking people’s code (passing fooStyle alongside other options was a noop before; now it throws) |
yea, I got https://bugs.chromium.org/p/chromium/issues/detail?id=1124778 today and I marked it as WaI |
@ljharb could you point out where are these reports ? I cannot find them in https://bugs.chromium.org/ beside the one above I mentioned. |
I don't have any links, only 3-5 reports in an irc channel. |
Discussion from 2020-09-10 TC39-TG2 meeting: The horse is out of the barn. Even if we stop throwing, there's still a version of Chrome and Firefox that have the exception. My conclusion is that we should use this as a learning experience to think more about the impact of changes like this to web compatibility and making it easier to use new features with the same code for both old and new browsers. |
We decided in #2 to ignore superfluous options when dateStyle/timeStyle was being used.
However, I had an idea about a reasonable behavior for combining the two, which also allows us to cover additional use cases. I'll go them one by one.
Omitting undesired fields
By default, all fields of the date and all fields of the time are shown. However, we have users at Google who may like to use dateStyle/timeStyle but show only a certain subset of fields. One way to allow this would be to allow users to "opt out" of fields when using dateStyle/timeStyle.
Suppose the user wrote code such as,
The expected output would then be a string with month and day but not year, formatted with the locale customs for short dates.
Overriding field widths
This is probably not as important of a use case, but it extends naturally from above. Suppose a user were to write,
The expected output here would be the appropriate long form for am/pm, but with the hour and minute (and second?) still shown in short form as is expected with timeStyle "short".
Implementation
There are workarounds to implement these features in ICU (basically round-tripping from pattern to skeleton back to pattern), but they are not as efficient as they could be. I have an upstream ticket where I am suggesting that the way dateStyle/timeStyle patterns are encoded into CLDR could be improved to allow the above cases: essentially, make dateStyle/timeStyle map to skeletons directly within CLDR (in a locale-dependent manner).
https://unicode-org.atlassian.net/browse/ICU-20710
I also filed a CLDR issue:
https://unicode-org.atlassian.net/browse/CLDR-13425
(Sorry to be raising this issue at Stage 3, but Anba's bug from implementing this in Firefox led to my line of thinking that made me raise this issue.)
The text was updated successfully, but these errors were encountered: