Code Monkey home page Code Monkey logo

node-geo-tz's Introduction

node-geo-tz

npm version Build Status Dependency Status Test Coverage

The most up-to-date and accurate node.js geographical timezone lookup package. It's fast too!

Install

npm install geo-tz

Usage

    const geoTz = require('geo-tz')

    geoTz(47.650499, -122.350070)  // ['America/Los_Angeles']
    geoTz(43.839319, 87.526148)  // ['Asia/Shanghai', 'Asia/Urumqi']

API Docs:

As of Version 5, the API now returns a list of possible timezones. There are certain coordinates where the timekeeping method will depend on the person you ask. Also, another case where 2 or more timezones could be returned is when a request is made with a coordinate that happens to be exactly on the border between two or more timezones.

geoTz(lat, lon)

Returns the timezone names found at lat, lon. The timezone names will be the timezone identifiers as defined in the timezone database. The underlying geographic data is obtained from the timezone-boudary-builder project.

This library does an exact geographic lookup which has tradeoffs. It is perhaps a little bit slower that other libraries, has a larger installation size on disk and cannot be used in the browser. However, the results are more accurate than other libraries that compromise by approximating the lookup of the data.

The data is indexed for fast analysis by caching subregions of geographic data when a precise lookup is needed.

geoTz.setCache(options || false)

By default, geoTz uses a cache that expires after 60 seconds. This method can be used to change the caching behavior using the following options:

  • expires - time in miliseconds to expire a cached file (cannot be used together with store)
  • preload - if set to true will attempt to cache all files (slow startup time and requires lots of memory)
  • store - offload the cache to a custom storage solution (must be compatible with the Map api)

Examples:

geoTz.setCache(false) // disable caching
geoTz.setCache({expires:120000}) // cache expires after 2 minutes
geoTz.setCache({expires:0}) // cache never expires
geoTz.setCache({expires:0,preload:true}) // cache never expires and preloads all files

let map = new Map();
geoTz.setCache({store:map}) // pass a Map-like storage object

Limitations

This library is not intended to be used in the browser due to the large amount of files that are included to perform exact geographic lookups.

An Important Note About Maintenance

Due to the ever-changing nature of timezone data, it is critical that you always use the latest version of this package. If you use old versions, there will be a few edge cases where the calculated time is wrong. If you use greenkeeper, please be sure to specify an exact target version so you will always get PR's for even patch-level releases.

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.