Created
March 30, 2015 17:33
-
-
Save birjj/d5ecaa76674982019a6e to your computer and use it in GitHub Desktop.
(Much) faster tzdetect.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var tzdetect = { | |
| tzs: moment.tz.names(), | |
| matches: function(){ | |
| return this.offsetToTimezone[(new Date()).getTimezoneOffset()]; | |
| } | |
| }; | |
| // compute (new Date()).getTimezoneOffset value for all timezones, store in tzdetect.offsetToTimezone | |
| (function(tzdetect){ | |
| var outp = {}, | |
| tzs = tzdetect.tzs; | |
| for (var i = 0; i < tzs.length; ++i) { | |
| var m = moment().tz(tzs[i]), | |
| offset = m._offset; | |
| if (!outp.hasOwnProperty(offset)) outp[offset] = []; | |
| outp[offset].push(tzs[i]); | |
| } | |
| tzdetect.offsetToTimezone = outp; | |
| })(tzdetect); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment