Theresa Theresa - 1 year ago 162
Javascript Question

How to shorten the timezone name list got from moment.js?

I am using moment.js ( the method I used is
) to retrieve the timezone name list which enumerates over 500 cities across the world. The long list makes it not very efficient for the users to pick up the desired timezone. The question is whether there is a way to cut down on the size of the list, meaning group the cities in the same timezone offset together.

Answer Source

This is something on the backlog for moment-timezone, in issue #227.

Below is the temporary workaround I provided there, which will shorten the list to 365 zone identifiers.

var names = Object.keys(
    .map(function(k) { return[k].split('|')[0]; })
    .filter(function(z) { return z.indexOf('/') >= 0; })

This removes links and abbreviated zones from the list. We recognize this is still not ideal, and will improve upon this in a future release.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download