Skip to content
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

Unexpected 24-hour time format in en-AU #675

Closed
pm7y opened this issue Mar 17, 2020 · 6 comments
Closed

Unexpected 24-hour time format in en-AU #675

pm7y opened this issue Mar 17, 2020 · 6 comments

Comments

@pm7y
Copy link

pm7y commented Mar 17, 2020

In Australia (en-AU) a 24-hr time string to represent midnight is expected to be 00:00. However, 24:00 is returned.

For example the following returns '24:00'...
DateTime.fromISO('00:00').toLocaleString({ ...DateTime.TIME_24_SIMPLE, locale: 'en-AU' });

whereas the following return '00:00'...
DateTime.fromISO('00:00').toLocaleString({ ...DateTime.TIME_24_SIMPLE, locale: 'en-GB' });

As far as I'm aware Australia also commonly expresses midnight as 00:00 not 24:00.

@icambron
Copy link
Member

icambron commented Mar 17, 2020

Unfortunately, the ICU data disagree:

new Intl.DateTimeFormat("en-AU", { hour: "numeric", minute: "numeric", hour12: false }).format(new Date(2020, 03, 07))
"24:00"

Luxon doesn't control that; the ICU data do. So some expert somewhere thinks that Aussie 24-hour time uses 24:00, not 00:00. I couldn't say, but that's just how Luxon works.

A workaround for newer browsers is to use hourCycle to override what ICU thinks the rules in AU are:

DateTime.fromISO('00:00').toLocaleString({ hour: "numeric", minute: "numeric", hourCycle: "h23", locale: 'en-AU' });
"00:00"

Unfortunately, you can't use the preset because it includes hour12 and the docs for hourCycle includes this:

the hour12 option takes precedence in case both options have been specified

I will soon switch the presets to use hourCycle instead of hour12 and then you'll be able to do this:

DateTime.fromISO('00:00').toLocaleString({ ...DateTime.TIME_24_SIMPLE, hourCycle: "h23", locale: 'en-AU' });

@pm7y
Copy link
Author

pm7y commented Mar 17, 2020

Thanks for the explanation. Sorry, my searching skills are failing me, but where about in the luxon codebase are the locale-specific settings you pull in from the ICU data? Or is that something the browser is doing?

@icambron
Copy link
Member

icambron commented Mar 17, 2020

It's something browser is doing. Luxon uses the Intl API, like in my first code snippet above. Then the browser uses its data, typically taken from ICU, to provide the strings.

@Agranom
Copy link

Agranom commented May 28, 2020

@icambron when are you going to add hourCycle ?

@icambron
Copy link
Member

@Agranom I'm not sure. I need to evaluate how widely it's supported on browsers.

@dlbass
Copy link

dlbass commented Jun 8, 2020

@icambron We have been ignoring complaints about this issue in our app for a while now, and just today decided to deal with it. After reading this thread, and then a bunch of fumbling through Unicode documentation we found this table (see Day Periods at the very bottom) showing that the ICU has the correct data. However, Chrome, Edge, and Android all display the incorrect 24:XX, while Firefox, Safari, and iOS display the expected 00:XX.

Your fix to add hourCycle: 'h23' solves the issue in Chrome and doesn't appear to cause any issues with the browsers that already display the time correctly. That fix is also documented in the Google Chrome Help forum.

MDN describes the behavior we see in Chromium, but I don't see the ICU data supporting Chromium's choice to show h24 over h23.

We use Luxon a lot, and really hope to be able to leverage hourCycle to fix this time display. Regardless of what is correct for the locale, being able to show the time how we want would be very handy.

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

No branches or pull requests

4 participants