Skip to content
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

moment.tz.names() - Possibly discrepencies between IANA tzdata and library's list #159

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

Comments

@kashifshamaz21
Copy link
Contributor

It seems like there is some sort of discrepency between the list of timezones returned by the API moment.tz.names() and those provided by IANA.
Below are my findings when i was looking to create a list of timezones for end-users to choose from:
(All data is with reference to latest tzdata: 2014j)

  1. moment.tz.names() returns list of timezone names supported by our library.
    Total zones count returned by the API: 582
  2. Another source for timezone list:
    https://github.com/moment/moment-timezone/blob/develop/data/meta/2014j.json
    Array length of above json: 416
  3. IANA resource: ftp://ftp.iana.org/tz/data/zone1970.tab
    Total zones count from above IANA file: 336

There definitely looks like something is odd as none of them match. On inspecting further, here are a few explanations for the discrepancy.

  1. moment.tz.names() lists ALL possible timezone names,i.e,
    a) it includes historical zones which maybe practically not used much. eg: Etc/GMT-14, Etc/GMT-13, Etc/GMT-12 etc.
    b) it has a separate array entry for zones which are actually linked to each other.
    eg: "Asia/Kathmandu", "Asia/Katmandu".

But then, the list present in 2) and 3) above should have atleast matched. The data present in meta/2014j.json has meta data about each zone, and it doesn't have timezones like Etc/GMT+xx which do not map to any country. Hence, atleast the timezone count of this, should have been same as that of IANA zone1970.tab.

Another example of mismatch:
Last entry in the JSON array in meta/2014j.json has a zone for "Africa/Harare", mapped to country code "ZW".
Per IANA zone1970.tab, there is no zone named "Africa/Harare" !!!
Mayber i'm missing something, but thought its worth to bring this up here.
Will keep digging into this to see if i can find some explanation/clues.

@kashifshamaz21
Copy link
Contributor Author

Running a grep -r "Africa/Harare" tzdata-2014j/ results in entries in three files: zone.tab, africa, NEWS

  1. zone.tab: This is a deprecated version and we should be referencing zone1970.tab instead. @timrwood Are we using zone.tab as the source of truth to build meta/2014j.json?
  2. africa: In this file, Africa/Harare is linked to Africa/Maputo. And in IANA database zone1970.tab, Africa/Maptuo is mapped to country code ZW. As mentioned earlier, zone1970.tab has no entry for Africa/Harare.

It would be great if moment-timezone's API, moment.tz.names() could be refactored to return an array of JSON, similar to whats represented in https://github.com/moment/moment-timezone/blob/develop/data/meta/2014j.json. And the values return by the API need not have separate entries for linked zones. Instead, for such zones, we can have the entry have a "links" property which lists the zones it is linked to. And as mentioned in #158, the response can have additional metadata for each zone: country name, country code etc. This will help in grouping zones by Country.
That way, the response of moment.tz.names() can be directly used to populate the list of timezone choices shown to end-users.

@kashifshamaz21
Copy link
Contributor Author

More digging and found some explanation:
The Grunt Build task (refer https://github.com/moment/moment-timezone/blob/develop/tasks/data-meta.js) that generates the meta data file(meta/2014j.json) clearly is reading data from zone.tab and not from zone1970.tab.
From the comments in these two meta files:

  1. zone.tab: This file is intended as a backward-compatibility aid for older programs. New programs should use zone1970.tab.
  2. zone1970.tab: This file contains a table where each row stands for a zone where civil time stamps have agreed since 1970.

@timrwood Is the reason we are using zone.tab to create our meta json, is to support backward-compatibility with older programs?
In any case i'm planning to build upon the grunt task you have, to generate a meta file with info about zones, based on zone1970.tab. While i'm at it, i'll also be adding the country-name value to the zones, so as to resolve #158 as well.

@timrwood
Copy link
Member

I did not know about zone1970.tab, looks like it was added about a month after tasks/data-meta.js was written. It first appears in 2014f.

I think we should switch the grunt meta task to use zone1970.tab moving forward.

@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