Giter Site home page Giter Site logo

List of timezones about moment-timezone HOT 9 CLOSED

moment avatar moment commented on May 23, 2024
List of timezones

from moment-timezone.

Comments (9)

brewhk-dev avatar brewhk-dev commented on May 23, 2024 12

There's now moment.tz.names()

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

from moment-timezone.

mattjohnsonpint avatar mattjohnsonpint commented on May 23, 2024

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.

from moment-timezone.

dorongutman avatar dorongutman commented on May 23, 2024

@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.

from moment-timezone.

timrwood avatar timrwood commented on May 23, 2024

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"...]

from moment-timezone.

dawnerd avatar dawnerd commented on May 23, 2024

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.

from moment-timezone.

mattjohnsonpint avatar mattjohnsonpint commented on May 23, 2024

@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?

from moment-timezone.

timrwood avatar timrwood commented on May 23, 2024

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.

from moment-timezone.

aaronmagi avatar aaronmagi commented on May 23, 2024

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

moment.tz.names()

from moment-timezone.

brewhk-dev avatar brewhk-dev commented on May 23, 2024

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

from moment-timezone.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.