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

Render 12/24 hour format according to user's preference #276

Open
silverwind opened this issue Mar 9, 2024 · 4 comments
Open

Render 12/24 hour format according to user's preference #276

silverwind opened this issue Mar 9, 2024 · 4 comments

Comments

@silverwind
Copy link

silverwind commented Mar 9, 2024

The element currently render the hour format according to the local of the provided lang attribute, which when en or en-US will uses 12h clock format which is unexpected for users who are living in a region where the 24h format is the predominant format. See Wikipedia on which regions use which hour format.

I therefor propose to render the hour format in the user's preferred format that they have set in their OS, as determinable by Intl APIs. Specifically DateTimeFormat() accepts a hour12 option and the option for this value is determinable via various means. There is also a newer hourCycle option which also supports the 11-hour format, but this API is not yet widely supported in browsers.

@silverwind silverwind changed the title Render 24h hour format according to user's preference Render 12/24 hour format according to user's preference Mar 9, 2024
@keithamus
Copy link
Member

All sounds very reasonable. PRs welcome!

@silverwind
Copy link
Author

silverwind commented Mar 11, 2024

I'll try. I think we could make it the default behaviour with an HTML attribute to opt-out, maybe call it strictLangFormatting which means it would strictly format with the detected lang attribute, like it currently does.

@keithamus
Copy link
Member

keithamus commented Mar 11, 2024

It could be opt-out by explicitly setting hour12 (or hourcycle) - where the default is automatically computed based on the locale.

Looks like it can also be overridden via hc extension key so e.g. en-gb-u-hc-h12 would force 12 hour formatting regardless of the hourcycle/hour12 options.

@silverwind
Copy link
Author

Interesting find with hc. It seems to work in the three major engines, so the opt-out could be with it.

$ eshost -e "new Intl.DateTimeFormat('en-gb-u-hc-h12', {hour: 'numeric'}).format()"
#### JavaScriptCore
1 PM

#### spidermonkey
1 pm

#### v8
1 pm
$ eshost -e "new Intl.DateTimeFormat('en-gb-u-hc-h23', {hour: 'numeric'}).format()"
#### JavaScriptCore
13

#### spidermonkey
13

#### v8
13

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

2 participants