Moment-timezone: List of timezones

Created on 29 Jul 2013  路  9Comments  路  Source: moment/moment-timezone

I'm looking for a way to output all added timezones, preferably ordered correctly. I didn't see any possible way right now.

Before I fork and patch, I wanted to ask if there was some way that maybe I looked past.

Most helpful comment

There's now moment.tz.names()

moment.tz.names(); // ["Africa/Abidjan", "Africa/Accra", "Africa/Addis_Ababa", ...]

All 9 comments

The tz data is just an object with a couple of big arrays. You can get at the zones easily with momentTZData.zones.

Regarding ordering "correctly" - I don't believe there is any particular sort order that is "correct" for IANA zone names. You could sort them alphabetically, or geographically, or by standard offset, or by current offset. Any would be acceptable.

If your intention is to produce a drop-down list for user selection of time zone, I would recommend you consider a map-based picker instead. They are much more user friendly. This one is my favorite but there are others out there.

@mj1856 I couldn't get momentTZData at all (except in the http://momentjs.com/timezone site).
Since there IS a need for getting the list of timzones, I don't see why not adding a getAll kind of method.

All the data is available in the moment-timezone.json file at the root of the repo.

I suppose we could expose a method that lists the names of all the installed zones and links in case someone wants to use the data builder to get a subset of all the data.

Something like this.

moment.tz.zones(); // ["Africa/Abidjan", "Africa/Accra", "Africa/Addis_Ababa"...]

I think exposing a method to get the data would be great. It's already there, just a private method.

Completely unrelated to this issue, but it would be nice to have a version of the zone name suitable for display in a UI, such as a dropdown.

@dawnerd - We only have what's provided by the TZDB. To get display names, we'd have to pull in language-specific CLDR data, which can be quite large.

There are quite a few projects that implement CLDR data in JavaScript. Here is one that appears to have time-zone specific translations separated out. You could use that data to build your dropdown. I have no idea how current that library is or if they stay on top of CLDR updates. There may be better ones somewhere.

@timrwood - Am I correct that you don't plan to pull CLDR localized translations of time zone display names into moment-timezone? Or is that something you want to consider to align with how moment localizations work?

Yeah, this is probably best left out of moment-timezone.

All the information needed to map a zone to a display name is available, and duplicating the efforts of CLDR from within this library doesn't really make sense.

There's now moment.tz.names()

moment.tz.names(); // ["Africa/Abidjan", "Africa/Accra", "Africa/Addis_Ababa", ...]

@brewhk-dev is this change checked into the latest release?

moment.tz.names()

@aaronmagi A quick check on the changelog.md tells me it was added in version 0.1.0 on 23rd June, 2014

Was this page helpful?
0 / 5 - 0 ratings