Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

PartitionDateTimeRangePattern may need additional date-time fields not present in the formatter #21

Closed
anba opened this issue May 27, 2020 · 6 comments · Fixed by #25
Closed

Comments

@anba
Copy link

anba commented May 27, 2020

Example:

js> var dtf = new Intl.DateTimeFormat("en", {hour: "numeric", timeZone: "UTC"})
js> dtf.resolvedOptions()
({locale:"en", calendar:"gregory", numberingSystem:"latn", timeZone:"UTC", hourCycle:"h12", hour12:true, hour:"numeric"})
js> dtf.formatRange(0, 24*60*60*1000)                                                               
"1/1/1970, 12 AM \u2013 1/2/1970, 12 AM"

The resolved pattern for the Intl.DateTimeFormatter only includes [[hour]], but to output the range more date-time fields are needed.


This can mean two things:

  1. Either restrict [[rangePatterns]] to only include fields present in the format fields record.
    1. For example the format fields record {[[hour]]: "numeric", [[minute]]: "2-digit", [[second]]: "2-digit", [[pattern]]: "{hour}:{minute}:{second}", [[pattern12]]: "{hour}:{minute}:{second} {ampm}"} can only support ranges in [[rangePatterns]] which contain hour, minute, and second.
    2. This mode isn't currently supported by ICU, though.
  2. Somehow create a separate Intl.DateTimeFormat instance in PartitionDateTimeRangePattern which supports all fields needed for [[rangePatterns]].
@anba
Copy link
Author

anba commented May 27, 2020

Or instead of a whole new separate Intl.DateTimeFormat instance, give the [[rangePatterns]] elements additional fields to define the date-time formats used within the ranges.

For example instead of the current:

[[rangePatterns]]:
    [[Hour]]:
        {[[Source]]: "startRange", [[Pattern]]: "{day}/{month}/{year}, {hour}:{minute}"}
        {[[Source]]: "shared", [[Pattern]]: " – "}
        {[[Source]]: "endRange", [[Pattern]]: "{hour}:{minute}"}
[...]

define it as

[[rangePatterns]]:
    [[Hour]]:
        [[day]]: "numeric"
        [[month]]: "numeric"
        [[year]]: "numeric"
        [[hour]]: "numeric"
        [[minute]]: "2-digit"
        {[[Source]]: "startRange", [[Pattern]]: "{day}/{month}/{year}, {hour}:{minute}"}
        {[[Source]]: "shared", [[Pattern]]: " – "}
        {[[Source]]: "endRange", [[Pattern]]: "{hour}:{minute}"}
[...]

and then use the additional fields within FormatDateTimePattern.

@anba
Copy link
Author

anba commented May 27, 2020

Hmm, ICU-based implementations can't even guarantee that the interval and non-interval string use the same output format for date-time fields:

js> var dtf = new Intl.DateTimeFormat("en", {day: "2-digit", timeZone: "UTC"})  
js> dtf.format(0)                                                   
"01"
js> dtf.formatRange(0, 24*60*60*1000)                                          
"1 \u2013 2"

2-digit is only used for the non-interval string, whereas the interval string uses numeric.

So, if we want to specify what's currently implementable using ICU, we need to allow to use different formats for the individual date-time components, which is possible with the proposal outlined in #21 (comment).

@anba
Copy link
Author

anba commented Jul 10, 2020

@FrankYFTang Was your comment meant for #22?

@FrankYFTang
Copy link
Contributor

FrankYFTang commented Jul 13, 2020

@FrankYFTang Was your comment meant for #22?

yes, sorry. I put into the wrong issue. Deleted that and added it to #22

fabalbon added a commit that referenced this issue Aug 13, 2020
…e date-range patterns (Issue #21).

Together with this, update FormatDateTimePattern to use these options instead of the default options used by date-time formatting.
@fabalbon
Copy link
Member

Thanks @anba for the suggestion, you are right that we are missing these date-time fields that would be necesary to format some of the possible date ranges.

I like your proposal as it would allow us to support current ICU behavior without needing to create a new dateTimeFormat in PartitionDateTimeRangePattern. I prepared #25 based on it.

@anba, @FrankYFTang I'd really appreciate if you could take a look at and review #25. Thanks!

@anba
Copy link
Author

anba commented Sep 8, 2020

A Firefox user also noticed that the date-time field formats can change depending on the input ranges: https://bugzilla.mozilla.org/show_bug.cgi?id=1659367

fabalbon added a commit that referenced this issue Jan 9, 2021
…e date-range patterns (Issue #21).

Together with this, update FormatDateTimePattern to use these options instead of the default options used by date-time formatting.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants