question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can Luxon retrieve a list of all valid timezone names?

See original GitHub issue

I’m trying to implement functionality in my app that allows the user to enter a local time, and then assign a custom timezone identifier for a different timezone (e.g. Asia/Ho_Chi_Minh).

I’m doing this so that due dates/times can be entered relative to a remote location without the user having to manually calculate what the local time of their current location would be at that instant (and maybe get it wrong due to DST changes, etc.).

Luxon lets me retrieve the timezone identifier for the current location:

DateTime.local().zoneName

but I’m having a hard time establishing whether or not Luxon will allow me to retrieve an entire list of all valid identifiers. There’s no obvious API call in the docs for this, and I’m mindful that as Luxon calls on the browser, it most likely doesn’t maintain its own list internally.

Is there a means of achieving this through Luxon? If not, are there any alternative recommendations for this need?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:21 (2 by maintainers)

github_iconTop GitHub Comments

28reactions
zdraganovcommented, Jul 23, 2019

I’m managed to get the list of supported timezones (and later cache it) using tzdata library and the following code snippet:

const {DateTime} = require('luxon')
const {zones} = require('tzdata')

const luxonValidTimezones = Object.entries(zones)
  .filter(([zoneName, v]) => Array.isArray(v))
  .map(([zoneName, v]) => zoneName)
  .filter(tz => DateTime.local().setZone(tz).isValid)
17reactions
justingolden21commented, Jul 2, 2021

Coming in from 2021 here to mention that getting a list of timezones would be useful, so we don’t need to copy from an external source, that source then needs to be updated and in sync with luxon, or use another external library which also needs to be in sync with luxon. Luxon already has the information (clearly, since it uses it) so not only should be be easy to add, but much lwoer file size than adding redundant data. Just my 2 cents, love luxon : )

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get list of all timezones in javascript - Stack Overflow
I recently created an array containing all timezones and found that a couple of official timezones were missing from Chromium 71.0.3578.98.
Read more >
luxon 3.1.1 | Documentation
If input is a string containing a valid time zone name, a Zone instance with that name is returned. If input is a...
Read more >
How to Handle Time Zones using DateTime and Luxon
The toLocaleString method returns a string with a language-sensitive representation of the Date object. At the same time, this method supports ...
Read more >
types/luxon - UNPKG
The CDN for @types/luxon. ... 45, * Return an array of eras, such as ['BC', 'AD']. ... 87, * * If `input` is...
Read more >
List of tz database time zones - Wikipedia
Country code(s) TZ database name Type STD DST CI, BF, GH, GM, GN, IS, ML, MR, SH, SL, SN, TG Africa/Abidjan Canonical +00:00 +0... GH...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found