moment-timezone: I don't see a way to get an easy list of the available timezones

My use case is populating a select element with options for the available timezones so the user can set their timezone. I was hoping for something along the lines of

moment.tz.getTimezones() which would return something like

[
    {
        name: "Eastern Standard Time"
      , locale: "America/New_York"
      , abbreviation: "EST"
      , offset: "-5"
    }
  , {
        name: "Central Standard Time"
      , abbreviation: "CST"
      , locale: "America/Chicago"
      , offset: "-6"
    }
]

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 24 (6 by maintainers)

Most upvoted comments

@elewin see #227. But also, listing out the IANA identifiers isn’t so great anyway. One needs CLDR data to do it right. There’s certainly room for a javascript-only version of something like my demo here.

Oh, and please don’t make a habit of commenting on years-old-closed issues. 😉

Using moment.tz.names() returns a list of over 500 elements, is it possible to condense that down so that there is just one for each zone? If this were to be used to populate a drop down to allow a user to select their timezone, then it would be completely impractical

This has been added in 0.1.0 as moment.tz.names().

http://momentjs.com/timezone/docs/#/data-loading/getting-zone-names/

Thank you for the response and the clarifications, my example was just a rough sketch of what was desired, pardon my misconceptions. I appreciate the work done on this library, this request should really just be considered an “enhancement” request, since it is not regarding anything wrong with moment-timezone.

I do believe that even something as simple as “an array of all of the time zone names that we know about, such as ["America/Chicago","Europe/London","Africa/Johannesburg"]” would be useful.

Regarding the offset being invalid, what about an “offset” and “offsetDST”, returning, say, -5 and -4 respectively?

Regarding the descriptions such as “Eastern Standard Time”, plugging “Москва, стандартное время” into Google translate outputs “Moscow Standard Time”, so it appears to simply be a 1:1 translation. Perhaps the library can simply return the English description and that can be handled by however an application chooses to do localization?

Lastly, regarding any of the data that would need a “point in time” for referencing, maybe it could be an optional parameter like moment.tz.getTimezones( referenceTime ), whereas moment.tz.getTimezones() would simply base it off the current date/time.

My use case for this was simply wanting to populate a select field on a web app with a list of selectable timezones for the user. Right now I have to make my own data structure, which is not a huge deal but if I add a new timezone to the zones data passed in to moment.tz.add then I have to remember to update my reference structure as well, which is not ideal.