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

Adding hooks for external libs to supply timezone name and timezone abbreviations #777

Merged
merged 1 commit into from May 23, 2013

Conversation

timrwood
Copy link
Member

This is to allow libs like moment-timezone and others to provide timezone information by overwriting moment.fn.zoneName and moment.fn.zoneAbbr.

@ichernev
Copy link
Contributor

I think this version should also print the local timezone. Where to get it with this (new Date()).toString().match(/\((.*)\)/)[1]. It can be cached once the library is loaded.

@timrwood
Copy link
Member Author

Well, the local timezone could be PDT or PST based on DST, so we should probably use the version that was deprecated with #162.

Basically just undo 9b56710, but in moment.fn.zoneAbbr.

@ichernev
Copy link
Contributor

So the moment-timezone will be distributed separately, and you can use moment without it? Also -- if you have any moment, you can get the Date and extract the timezone, no matter what the DST is now (or was at some point). So I guess it won't be cached, but it would still be correct. We can fallback to GMT/UTC+-NNNN if we can not extract anything, that would still provide a timezone specifier, maybe not very compact but at least not wrong.

@timrwood
Copy link
Member Author

Actually, now that I think about it, it's probably best not to add support for timezone abbreviations in the core lib.

As noted in #162, browser support for getting the timezone name is very inconsistant, even inconsistent across different timezones.

The good thing is that adding these hooks will make it easier for someone to take a library like jstimezonedetect and add a moment.js hook for getting the timezone name.

We could even add a link to a gist that adds support for getting timezones based on the Date.prototype.toString hack, but I think it's too buggy to be a part of the core lib.

@ichernev
Copy link
Contributor

Well. then the only thing that needs to be part of the core lib is the z/zz format tokens, because the functions can be added by any plugin anyway. And if that's the case I'd think about a generic way of adding format (and maybe parse) tokens through plugins.

timrwood added a commit that referenced this pull request May 23, 2013
Adding hooks for external libs to supply timezone name and timezone abbreviations
@timrwood timrwood merged commit 96b90aa into develop May 23, 2013
@mattjohnsonpint
Copy link
Contributor

Tim, one thing that would help is if you could please be consistent in terminology. When I hear the terms "zone" or "time zone", I think of a named time zone like America/New_York. When I see a value like -04:00, I prefer to call that an "offset" to avoid confusion. Since many zones have multiple offsets, it gets confusing when these terms get mixed up. In wrote this up as "TimeZone != Offset" as part of the TimeZone tag wiki on StackOverflow. Thanks.

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

Successfully merging this pull request may close these issues.

None yet

3 participants