-
Notifications
You must be signed in to change notification settings - Fork 77
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
[Time Picker / Input Time Picker / Input type="time"] Handle 24 hour format #4756
Comments
@annierm18 Can you confirm if this needs to be configurable? So far, the format has been automatically determined by the locale. |
Sounds like the issue is just that the component doesn't respond to browser or OS locale changes properly. Is that correct? |
From the looks of it, this doesn't seem possible to do with the existing browser APIs. I'm going to do some more research, but I don't think there's a way to access this system setting via javascript in the browser. |
IIRC Last time I looked into this I found it really depends on the browser and OS. For example, FireFox:
https://firefox-source-docs.mozilla.org/intl/locale.html#regional-preferences @macandcheese said he is using Mac/Chrome: Where as it looks like Chrome won't use Window's system settings and you have to make shortcuts: I don't think input uses |
Yeah, and even if the specific browser provides a hook into the OS locale, which would imply a default hour cycle, it would still need to hook into the OS hour cycle checkbox to determine if a user has overridden the default. |
Thank you for the info @eriklharper and @benelan! I will discuss this with Babak and will follow up soon. |
Update on this - the i18n team would like for this to be implemented if it's possible. |
What we can support is an Would a property that overrides the existing locale's hour cycle suffice? |
I'm pretty sure it's possible using /*
* Detects navigator locale 24h time preference
* It works by checking whether hour output contains AM ('1 AM' or '01 h')
* based on the user's preferred language
*/
const isBrowserLocale24h = () =>
!new Intl.DateTimeFormat(navigator.language, { hour: "numeric" })
.format(0)
.match(/AM/); |
Looking at the guys code you would probably have to check for "PM" too: const isBrowserLocale24h = () =>
!new Intl.DateTimeFormat(navigator.language, { hour: "numeric" })
.format(0)
.match(/[AM|PM]/); |
Alright I tested the guys code and it doesn't work at all lol. The AM/PM string is dependant on the locale. This seems to work based on my limited testing const isBrowserLocale24h = () =>
!new Intl.DateTimeFormat(navigator.language, { hour: "numeric" })
.format(new Date(1, 1, 1, 14))
.match(new RegExp(Number(2).toLocaleString(navigator.language))); I think using the code above by default would be good, but there is still the case of the OS/browser combos that don't use the locale system settings. So I could see Erik's prop recommendation as well. Thoughts @jcfranco ? |
Correct, I wouldn't expect this to work anyway because |
That code snippet won't work consistently enough to rely on it. Didn't work for me when I changed my OS time preference to 24 hour with an en-US locale. |
Yeah I'm starting to think Chrome's documentation lied to me. Here it says:
I have Windows, but I asked Franco to change his system language to Spanish and Chrome did not automatically display in Spanish. My understanding is that |
The kicker there is "default system language". The trick is getting it to recognize the non-default hour setting, which it doesn't appear to support. |
Implementing support an for hour-cycle property that @eriklharper mentioned sounds like a good option |
Yes, we would use this to set the default value of the |
Update: Almost done writing tests for all the supported locales, and looking at a handful of some locale-specific issues with typing in localized meridiem characters and one with the arab numbering-system, and then refactoring from |
**Related Issue:** #4756 ## Summary This PR exposes a new `hour-format` property to `input-time-picker` and `time-picker` that overrides the locale's default `hourCycle` setting, allowing a 12-hour locale to be formatted in 24-hour time and vice versa. Confirmed with the i18n team that the bulgarian `ч.` character (abbreviation for "hours") should not display for short and medium time formats. --------- Co-authored-by: Kitty Hurley <[email protected]>
Installed and assigned for verification. |
@eriklharper I'm encountering what may be unexpected behavior with the component when Sample with |
Nice catch there. Not expected for sure. Seems to be an initial state kind of behavior where the formatting is displaying as the default 12-hour even though the correct 24-hour hour value is being correctly stored. Looks like that behavior ceases in subsequent updates, but agreed that this isn't expected. I would call this a bug for sure, probably low-ish on the severity, but definitely something we should fix. |
Created #11198 to address the unrelated behavior for 25.R1. Closing out the remaining effort above as complete and verified. 🎉 |
Description
Currently, the time-picker, input-time-picker, and input type="time" do not allow for the use of 24 hour time format from an end-user use case.
Acceptance Criteria
Allow the ability to control the format - 12/24hr, in these components / component configurations.
Relevant Info
A native (non-calcite) input of type="time" automatically changes from 12 -> 24 hour format when I changed my Time Format in OS preferences to 24-hour time (Mac / Chrome). I could not replicate this behavior with calcite-input of type time.
Which Component
[Time Picker / Input Time Picker / Input type="time"]
Example Use Case
No response
The text was updated successfully, but these errors were encountered: