-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3e5770b
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
tzdetect.js | ||
=========== | ||
|
||
Goals | ||
----- | ||
|
||
* detect the user timezone, or more precisely list all IANA time zone ids that are compatible with the running javascript engine | ||
* limit data duplication by using the Moment.js version of the Olson tables | ||
|
||
Demo | ||
---- | ||
|
||
See http://dystroy.org/stackoverflow/timezonedetect.html | ||
|
||
Usage | ||
----- | ||
|
||
<script src="moment-with-langs.min.js"></script> | ||
<script src="moment-timezone-with-data.min.js"></script> | ||
<script src="tzdetect.js"></script> | ||
<script> | ||
var tzid = tzdetect.matches()[0]; // for example : "Europe/Paris" | ||
</script> | ||
|
||
Related | ||
------- | ||
|
||
http://stackoverflow.com/questions/19420582/detect-the-id-of-the-current-user-timezone-using-moment-js |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "moment-tzdetect", | ||
"version": "0.1.0", | ||
"homepage": "https://github.com/jamesjieye/tzdetect.js", | ||
"authors": [ | ||
"Canop <[email protected]>" | ||
], | ||
"description": "A JavaScript library to detect the timezone using Moment.js", | ||
"main": "tzdetect.js", | ||
"keywords": [ | ||
"moment", | ||
"timezone" | ||
], | ||
"license": "MIT", | ||
"ignore": [ | ||
"**/.*", | ||
"node_modules", | ||
"bower_components", | ||
"test", | ||
"tests" | ||
] | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// A small public domain library detecting the user's timezone using moment.js | ||
// Repository : https://github.com/Canop/tzdetect.js | ||
// Usage : | ||
// tzdetect.matches() : array of all timezones matching the user's one | ||
// tzdetect.matches(base) : array of all timezones matching the supplied one | ||
var tzdetect = { | ||
names: moment.tz.names(), | ||
matches: function(base){ | ||
var results = [], now = Date.now(), makekey = function(id){ | ||
return [0, 4, 8, -5*12, 4-5*12, 8-5*12, 4-2*12, 8-2*12].map(function(months){ | ||
var m = moment(now + months*30*24*60*60*1000); | ||
if (id) m.tz(id); | ||
return m.format("DDHHmm"); | ||
}).join(' '); | ||
}, lockey = makekey(base); | ||
tzdetect.names.forEach(function(id){ | ||
if (makekey(id)===lockey) results.push(id); | ||
}); | ||
return results; | ||
} | ||
}; |