guess-timezone

0.2.1 • Public • Published

guess-timezone NPM version Build Status Dependency Status

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

Install

npm i -S guess-timezone

Usage

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'

Methods

calc

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.

setWhitelist ([Array whitelist])

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.

unsetWhitelist

Removes the previously set whitelist.

Tests

Tests in tape. They can be run with npm test.

Tests can be run in a loop with npm run tdd

Developing

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

Requirements

  • 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

License

Artistic 2.0 © Joey Baker

Package Sidebar

Install

npm i guess-timezone

Weekly Downloads

11

Version

0.2.1

License

Artistic-2.0

Last publish

Collaborators

  • joeybaker