Skip to content
This repository was archived by the owner on Apr 14, 2021. It is now read-only.

hour12 should be taken into consideration when searching for best match format #119

Open
caridy opened this issue Jul 7, 2015 · 1 comment

Comments

@caridy
Copy link
Collaborator

caridy commented Jul 7, 2015

this is related to issue #109

@andyearnshaw I have done some debugging on the issue described in issue #109, and here are some preliminary thoughts:

When trying to format a time in french using this code:

new IntlPolyfill.DateTimeFormat('fr-FR', {
    hour: 'numeric',
    minute: 'numeric'
}).format(new Date('2000/12/12 09:09'));

It will resolve to one of the formats under availableFormats, specifically, the pattern "h:mm a" from this line:

"hm": "h:mm a",

As a result, the internal representation of the format is:

{ 
    hour: 'numeric',
    minute: '2-digit',
    pattern: '{hour}:{minute}',
    hour12: true,
    pattern12: '{hour}:{minute} {ampm}' 
}

Interestingly, the output is what we have in pattern, instead of pattern12, which conflicts with the default value of hour12 for that locale, and the entry in the resolved format which is set to true as well. I will expect this to use pattern12 instead. But even if we fix that, the main problem remains, which is, hour should have been set to 2-digit instead of numeric.

More investigation on this shows that if we modify the options to set hour to 2-digit explicitly, as in the following code:

new IntlPolyfill.DateTimeFormat('fr-FR', {
    hour: '2-digit',
    minute: 'numeric'
}).format(new Date('2000/12/12 09:09'));

It resolves to another format, this time the correct one, which correspond to the short entry in timeFormats, which is equal to: "HH:mm", link here:

"short": "HH:mm"

As a result, it produces this:

{ 
    hour: '2-digit',
    minute: '2-digit',
    pattern: '{hour}:{minute}'
}

And everything looks correct.

When analyzing the difference in weight from the two patterns for the first example, I found something weird when debugging the best match for the following structure:

{ 
  '[[weekday]]': undefined,
  '[[era]]': undefined,
  '[[year]]': undefined,
  '[[month]]': undefined,
  '[[day]]': undefined,
  '[[hour]]': 'numeric',
  '[[minute]]': 'numeric',
  '[[second]]': undefined,
  '[[timeZoneName]]': undefined
}

[[hour12]] is not taken in consideration for the weighting, as a result, the following format weight less

{ 
  hour: '2-digit',
  minute: '2-digit',
  hour12: false,
  pattern: '{hour}:{minute}'
}

than

{
  hour: 'numeric',
  minute: '2-digit',
  pattern: '{hour}:{minute}',
  hour12: true,
  pattern12: '{hour}:{minute} {ampm}'
}

which makes sense, but if hour12 were considered, they should have similar weight, and the first one matches the hour12 value. I wonder if we are missing something here.

@caridy
Copy link
Collaborator Author

caridy commented May 12, 2016

This is now taken into consideration for bestFit algo in #171

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant