Skip to content

Add Country name & country code to zone names #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kashifshamaz21 opened this issue Dec 10, 2014 · 4 comments
Closed

Add Country name & country code to zone names #158

kashifshamaz21 opened this issue Dec 10, 2014 · 4 comments

Comments

@kashifshamaz21
Copy link
Contributor

Moment Timezone currently provides a list of zone names via this API: moment.tz.names();

But when a list of choices is to be displayed to end-user, a better selection experience would be to have a two-step selection:

  1. First select country.
  2. Based on selected country, populate the second list containing timezones of that country.
    Ex: Google calendar timezone selection

To achieve this, the zones list that moment timezone provides, needs additional information about the countries in which it is used.
This bit of info is publicly available in the IANA data repo

  1. List of countries with country codes: ftp://ftp.iana.org/tz/data/iso3166.tab
  2. Mapping between country and zone names: ftp://ftp.iana.org/tz/data/zone1970.tab
@timrwood
Copy link
Member

@kashifshamaz21
Copy link
Contributor Author

@timrwood Thanks for telling about this..
But it seems like the JSON blob only has country code for the zones.
a) that would mean, to achieve something like what i described in the issue description, would need maintaining another mapping of country code with the country name.
b) Would it be good to have a separate API, similar to moment.tz.names(); that provides array of zone objects containing the zone name, and meta data like country code, country name.

Because of problem a) with the meta/latest.json, i'm currently thinking about having a script to parse the info from IANA data files, to construct a JSON which can serve this purpose.
Would be awesome if we can add this functionality to this library itself.

@kashifshamaz21
Copy link
Contributor Author

@timrwood Now that we have something going for this feature, have been thinking on how we can make this a part of the library itself.
Firstly, very impressed by the "packing" of data that you have done to bring down the bytes to be loaded on the client.
Why don't we merge the meta-data with the timezone data itself? Because as such, the meta-data won't be used if the utility methods that are needed to consume it are not inherently part of the libraries API set.
Here are the suggestions:
Current format of unpacked data data/unpacked/2014f.json is:

{
  "version": "2014j",
  "zones": [],
  "links":[]
}

we can add the countries hash from the meta-data to this. And the countries array to every zone. (merging metadata with the timezone data)
Now as for the packing(compressing) of this new metadata, it could be done this way:

  1. For each zone, append a space separated list of countries in which its used.
  2. In the new countries hash, the keys are country codes and their values are strings encoded as:
    "countryCode": "abbr|name|{space-separated-list-of-zones}"
{
   "version": "2014j",
   "zones": [
      "Africa/Abidjan|LMT GMT|g.8 0|01|-2ldXH.Q|CI BF GM GN ML MR SH SL SN ST TG"
      ....
   ],
   "countries": {
      "US": "US|United States|America/New_York America/Detroit|............ Pacific/Honolulu"
      ....
   },
   "links": []

With the packed data in above format, some very useful APIs can be added:

  1. List of timezones(moment.tz.zones()): This would return list of "zone objects" with following info
{ 
   name: "Africa/Abidjan",
   abbr: "GMT",
   offset: "000", // current GMT offset effective in this zone
   countries: ["CI", "BF", "GM", "GN", "ML", "MR", "SH", "SL", "SN", "ST ,"TG"]
}

The abbr and offset in the above hash can be easily determined as follows

zoneAbbr = moment.tz.zone('Africa/Abidjan').abbr(moment.utc().valueOf());
currentOffset = moment.tz.zone('Africa/Abidjan').offset(moment.utc().valueOf());
  1. List of countries(moment.tz.countries()): This would retun list of country codes and their names.
  2. Zones of a country(moment.tz.zonesInCountry()): This would return all "zone objects" of a particular country.

I'm willing to put my hand up for adding all the "packing/unpacking" as well as the new APIs for this.
My aim is that, moment-timezone can be made as the library that deals with ever-so-painful timezones.
Let me know if you see value in this proposal.

@timrwood
Copy link
Member

Closed with #162

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants