-
Notifications
You must be signed in to change notification settings - Fork 110
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
Ability to get a list of all timeZones? #122
Comments
date-fns-tz doesn't store timezones, so I believe you have to store it locally or fetch them via an API. Since a basic timezone string (e.g., To get the user's local timezone from the browser API: Here's a list of timezone strings in the same format: https://stackoverflow.com/a/54500197 You could enrich and order this list fairly easily with something like the following. (You can also search the web for a json with the offsets stored alongside the strings — the downside is that some of these values change over time with laws and regulation (hopefully the strings themselves change less).
|
Moment.js has this feature: https://momentjs.com/timezone/docs/#/data-loading/getting-zone-names/ Sad to see that |
|
This feels awkward to have to store the TZ list in the code, while either This doesn't respect the single source of truth paradigm. |
In case this helps anyone who comes to this thread, here's how we can obtain all timezones with the const timeZones = Intl.supportedValuesOf('timeZone'); You can read more about it in the MDN docs. |
With this library, is it possible to get a list of all timzeones?
E.g. in your examples there are some like
instead of putting a string, could I somehow use a variable from the library which corresponds to 'Africa/Johannesburg'?
Use Case:
Let's say there is a select with a list of timezones. Although I could just create array of timezones myself, I would have much more confidence if I could import this list from
date-fns-tz
; It means that if anything is changed inside the library, this list of timezones would be updated as well. Also it would ensure that it is working fine and is taking expected time zone name.The text was updated successfully, but these errors were encountered: