Make a best guess of the user's timezone. Uses the Intl API if avaliable. Works on the client and the server.
Table of Contents generated with DocToc
npm i -S guess-timezone
var guessTimezone = require('guess-timezone')
guessTimezone.setWhitelist() // now will only return US timezones
guessTimezone.setWhitelist(['Europe/London', 'America/New_York']) // will now only return one of these two timezones
guessTimezone.unsetWhitelist() // any timezone is now valid
guessTimezone.calc()
// 'America/Los_Angeles'
Returns the best guess of the current timezone. If the Intl
API caniuse data is available, it is used, and the timezone is very accurate. Else, the timezone is guessed from the timezone offset.
If the Intl
API isn't used, limits the timezones that the calc
method will return. This is desirable because if the timezone needs to be guessed, many offsets can match the user's offset.
If called without an argument, limits to the most common US timezones. If called with an array, limits to those timezones. Timezones must be strings in Olson TZID format.
Removes the previously set whitelist.
Tests in tape. They can be run with npm test
.
Tests can be run in a loop with npm run tdd
To publish, run npm run release -- [{patch,minor,major}]
NOTE: you might need to sudo ln -s /usr/local/bin/node /usr/bin/node
to ensure node is in your path for the git hooks to work
- npm > 2.0.0 So that passing args to a npm script will work.
npm i -g npm
- git > 1.8.3 So that
git push --follow-tags
will work.brew install git
Artistic 2.0 © Joey Baker