ecma402 icon indicating copy to clipboard operation
ecma402 copied to clipboard

How to select "glue pattern"?

Open FrankYFTang opened this issue 5 years ago • 6 comments

Spin off from https://github.com/tc39/ecma402/issues/190

The issue is what part of the specification decide which glue pattern should be used.

@caridy commented on Oct 27, 2017

In most cases, you can get away with transforming a pattern/skeleton into a DateTimeFormat options, specially if you're flexible with the output. E.g.:

var f = {
  weekday: 'long',
  month: 'long',
  day: 'numeric',
  year: 'numeric',
  hour: 'numeric',
  minute: '2-digit',
  second: '2-digit',
  hour12: true,
  timeZoneName: 'long'
};

new Intl.DateTimeFormat('en-US', f).format(Date.now()) "Friday, October 27, 2017, 4:14:53 PM Eastern Daylight Time" Most browsers, today, will add a comma after the year (IE11 does something slightly different) for that set of options. But if you look at the latest ICU library, we see this pattern: "EEEE, MMMM d, y 'at' h:mm:ss a zzzz", which does have an at in between and no coma for en-US.

I wrote some experimental library to try to see if we can help people who want to use patterns/skeleton for convenience, but still preserving the invariants of Intl to do the right thing depending of the locale.

https://github.com/caridy/intl-datetimeformat-pattern

With a library like this, you can get from that pattern/skeleton to the most likely option object that will produce something very similar, but in some cases slightly different due to the those weird differences.

I wonder if someone can actually explain the difference between ICU and browsers for something like the example above?

@jungshik ommented on Nov 22, 2017

@rxaviers is right on 'at' for en-US and CLDR 'glue pattern'. The fact that v8 does not do that is a bug. I thought I had filed a bug on that against v8, but I couldn't find it. Filed https://bugs.chromium.org/p/v8/issues/detail?id=7116 .BTW, this issue is not about 'skeleton' (#189) but about 'pattern'. The former (skeleton) will take a list of fields and field lengths and produce locale-dependent output (order can be shuffled, for instance).

@FrankYFTang wrote:

https://github.com/unicode-cldr/cldr-dates-full/blob/32.0.0/main/en/ca-gregorian.json#L335 show me

"dateTimeFormats": {
"full": "{1} 'at' {0}",
"long": "{1} 'at' {0}",
"medium": "{1}, {0}",
"short": "{1}, {0}",

It is not clear to me which part of the specification determine WHICH glue pattern it should use? Why should it use the "full" one but not the "short" one?

FrankYFTang avatar Apr 04 '19 23:04 FrankYFTang

ECMA-402 Recommendation (July 2019): update the spec to reflect ICU behavior.

sffc avatar Aug 07 '19 20:08 sffc

@fabalbon - this is related to the issue you talk about the "at" issue.

FrankYFTang avatar Aug 08 '19 17:08 FrankYFTang

@FrankYFTang What is the ICU4C behavior?

@zbraniecki What is the ICU4X behavior?

sffc avatar Sep 18 '23 23:09 sffc

The ICU glue pattern selection code is in source/i18n/smpdtfmt.cpp#L771

It need a closer look to figure what that code is doing

if ((timeStyle != kNone) && (dateStyle != kNone)) {
...
}

FrankYFTang avatar Sep 18 '23 23:09 FrankYFTang

ICU4X uses the date length

https://github.com/unicode-org/icu4x/blob/4242dfbdc7938d036565374e973e37d97b911f41/components/datetime/src/provider/date_time.rs#L213

sffc avatar Feb 23 '24 00:02 sffc

@ben-allen to update the spec to reflect this behavior (select glue pattern based on date length).

sffc avatar Feb 23 '24 00:02 sffc

This appears to have been fixed by Zibi in 2021 (commit 20c03597d80645f9be5c310820f114b59695beed), which correctly uses the date style to select a pattern from one of [[full]], [[long]], [[medium]], and [[short]]. I've put up PR https://github.com/tc39/ecma402/pull/886 to clarify the wording, which seemed to suggest that the field [[DateTimeFormat]] directly contained the pattern string, rather than a Record containing the pattern strings for each date style:

ben-allen avatar May 02 '24 16:05 ben-allen

Completed by Zibi in 2021 (commit 20c0359), wording clarification added in #886

ben-allen avatar May 09 '24 21:05 ben-allen