Too difficult to set 24h clock, it should be set in the locale definition
MorgusLethe opened this issue · 5 comments
My goal
I want to display localized time on my X axis (dates). I create my locale definition, and call d3.timeFormatDefaultLocale(myLocaleDefinition)
. It works and is almost perfect, I can see localized names of days and months, but hours are in 12 hour time (AM and PM). Even though my locale uses 24 hour time, I was forced to include a "periods" property in my definition, or else I would get an error.
The problem
The default time formatter wants to use the 12 hour clock (it uses "%I %p" for hours). If I want to use a 24 hour clock (and omit the incorrect "periods" property from my locale definition), I have to create my own time formatter, right?
The problem is that this is too difficult. It took me 3 hours of reading the documentation and examples to even understand where the problem is and what a time formatter is. I could not find a single example of a locale definition that does not use "periods". I realized later that using "periods" is required. Why?
In the documentation Russian is used as an example, but I don't think russians use 12h clock! And when I check the list of locales, every single one of them uses periods. Do the Germans, Spanish, Italians, Czechs, French and Russians all use AM and PM? I am sure they don't, and if so, that property should not be there, and it should default to 24h clock or force the use of another property.
TL;DR I want to use 24h clock just from the locale definition, not by researching and creating an entire new time formatter, and being confused by strange examples
Thanks for your help and understanding.
Thanks for the feedback. If you wish to improve the documentation and examples of an open-source project, I recommend you contribute by way of opening a pull request!
However, please be aware that this library in particular is likely to be archived in the future in favor of JavaScript’s standard date.toLocaleString. You can read about that here:
@MorgusLethe Did u archive that? I run into the same issue, want to use 24hours format. Any idea would be appreciated
Sorry, I don't remember and I no longer work at that company, so I don't have access to project... Good luck anyway :/
Oh thanks. So sad :(
What periods value can be used for 24h format? Empty array results in PM being indistinguishable from AM. Im guessing periods: ["", x]
where x is something special to add 12 to the PM hour