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
Get time zone(s) from abbreviation and country code #289
Comments
And which of the five "CST" time zones should we return? China? Cuba? What about "BST", British Summer Time, or Bangladesh Standard Time? There are just too many ambiguities, so no, we can't do this reliably. At least not without some other qualifier, such as country code. |
I've got the country code. Is it still possible to use timezone then? |
We don't have this capability today, but I'll leave this open as a feature request. |
Note, there will still be some ambiguities, such as |
@mj1856 , that would good enough! Thanks |
Any ETA on release? |
Consider it on the backlog, but I'm not actively working on it. A PR would be welcome! |
Maybe this could help |
Thanks, but how would it help? |
It is a complete list of timezones, you can't search for the country code
|
@asantos00 - Thanks, but that won't help. That's an outdated list of Windows time zone identifiers from a non-authoritative source, with lots of missing data and invented abbreviations. I can guarantee you any system using that file is going to have problems. moment-timezone is based on standardized IANA time zones. I recommend you read https://en.wikipedia.org/wiki/Tz_database and http://stackoverflow.com/tags/timezone/info |
@mj1856 oh, yeah, you're right, sorry for the bad suggestion! |
Is this feature still needed? This would be my first pull request but I would like to give it a go? |
@alexgrace95 yes, it is needed! |
Great I can do this and it seems a nice first pull request project. |
@alexgrace95 yes, it does completely. |
And for telephone country codes, we have NANP countries (North American Numbering Plan) that all use Perhaps you can include NANP entries matching to the four-digit codes. E.g. Jamaica would be |
@alexgrace95 - Thanks for your enthusiasm, but much of what you propose is out of scope. Telephone codes and geotags are not something that belong with this functionality. If one needs to map telephone code to country code, they can do that separately, and then later deal with time zone. Also, please don't go and build a spreadsheet of data to send a PR. The problem with building any mappings manually, is that they have to not only be painstakingly researched, but they also have to be maintained over time. Things change, and sometimes opinions influence the data. A library like moment can really only use data from either IANA or CLDR sources. In this particular case, it would be sufficient to use the country data for the limit subset of zones in the Since we're already using IANA data, it's really just a matter of adding a country-code element to the time zone data during the build process, and exposing some functions to use that field along with the existing zone and abbreviation data. I think this would be small enough to do without introducing another plugin. It's not really all that complex. |
@mj1856 - Thanks for your description and feedback, it all makes sense. Are you happy for me to do a PR to implement using country codes from the IANA data? |
That would be greatly appreciated! Take a look at the packed and unpacked formats in the docs. Essentially, you'd be adding a |
Also, I see that we're already extracting the countries from zone.tab and placing it in the "meta" files here: https://github.com/moment/moment-timezone/tree/develop/data/meta I'm not sure how we're using those presently, but I know they don't get shipped with the normal moment-timezone-with-data distributions. You should be able to hook into the existing build process to grab the country code and push it into the regular zone data. |
Okay I will do the work this weekend. Thanks for all your support |
Hi, I am still working on this but I am quite busy at the moment, hope to have the feature completed soon and the documentation updated. |
Pull Request has been submitted and is passing all checks: Please feel free to review and let me know if there is anything that can be improved or any functionality to be added 👍 I hope this will be useful and is what people wanted. Sorry it has taken a while to finish, I have been moving house as well as working full time with a long commute! As I have said before this is my first Pull Request and I appreciate any feedback |
Pull Request has been submitted and is passing all checks: Appreciate any feedback! |
Any movement on this? |
Until the PR is merged, if you're using Webpack or similar, you can directly use built-in data like this : import { zones } from 'moment-timezone/data/meta/latest.json';
function getCountryCode(zone) {
return zones[zone] && zones[zone].countries[0];
}
getCountryCode(date.tz()) |
Moment Timezone has the country data exposed since version |
The question is not silly at all, I also need a solution.
Thank you. |
I have an abbreviation (e.g. "PST"), need to get timezone from that. Is that possible with moment-timezone?
The text was updated successfully, but these errors were encountered: