Giter Site home page Giter Site logo

guess-timezone's Introduction

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

guess-timezone's People

Contributors

joeybaker avatar

Stargazers

Jannis R avatar Csongor Széles avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.