• This repository has been archived on 31/Aug/2021
  • Stars
    star
    208
  • Rank 189,015 (Top 4 %)
  • Language
    JavaScript
  • License
    Creative Commons ...
  • Created about 12 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JavaScript Library for Timezone Lookup by Location

tz-lookup

This is a little Javascript library that allows you to look up the time zone of a location given its latitude and longitude. It works in both the browser and in Node.JS, and is very fast and lightweight (~71KB) given what it does. We use it in production for The Dark Sky API.

This library is no longer actively maintained under an Open Source license. Please fork it if you would like to continue development.

Usage

To install:

npm install tz-lookup

Node.JS usage:

var tzlookup = require("tz-lookup");
console.log(tzlookup(42.7235, -73.6931)); // prints "America/New_York"

Browser usage:

<script src="tz.js"></script>
<script>
alert(tzlookup(42.7235, -73.6931)); // alerts "America/New_York"
</script>

Please take note of the following:

  • The exported function call will throw an error if the latitude or longitude provided are NaN or out of bounds. Otherwise, it will never throw an error and will always return an IANA timezone database string. (Barring bugs.)

  • The timezones returned by this module are approximate: since the timezone database is so large, lossy compression is necessary for a small footprint and fast lookups. Expect errors near timezone borders far away from populated areas. However, for most use-cases, this module's accuracy should be adequate.

    If you find a real-world case where this module's accuracy is inadequate, please open an issue (or, better yet, submit a pull request with a failing test) and I'll see what I can do to increase the accuracy for you.

Sources

Timezone data is sourced from Evan Siroky's timezone-boundary-builder. The database was last updated on 6 Jan 2019.

To regenerate the library's database yourself, you will need to install GDAL:

$ brew install gdal # on Mac OS X
$ sudo apt install gdal-bin # on Ubuntu

Then, simply execute rebuild.sh. Expect it to take 10-30 minutes, depending on your network connection and CPU.

License

To the extent possible by law, The Dark Sky Company, LLC has waived all copyright and related or neighboring rights to this library.

More Repositories

1

skycons

JavaScript
1,249
star
2

delaunay-fast

Fast Delaunay Triangulation in JavaScript.
JavaScript
778
star
3

string-hash

Fast string hashing function for Node.JS.
JavaScript
309
star
4

forecast-ruby

Ruby gem for retrieving data from the Forecast Weather API.
Ruby
240
star
5

translations

translate Dark Sky API summaries into any language
JavaScript
139
star
6

sphere-knn

Find the k nearest neighbors for points on a sphere.
JavaScript
121
star
7

binary-search

Tiny binary search library for Node.JS.
JavaScript
85
star
8

pngparse

100%-JavaScript PNG Parser for Node.JS
JavaScript
78
star
9

darksky-ruby

Ruby gem for retrieving data from the Dark Sky API
Ruby
48
star
10

astro

JavaScript
30
star
11

delaunay

Delaunay triangulation in arbitrary dimensions.
JavaScript
23
star
12

inhabited

quickly determine if a lat/lon may be inhabited or not
JavaScript
18
star
13

node-sarra

consume data from Environment and Climate Change Canada
JavaScript
13
star
14

metaregexp

A simple way to keep long regexes organized.
JavaScript
9
star
15

lowres-rgeo

low resolution reverse geocoder for Node.JS
JavaScript
9
star
16

elevation

Finds the elevation of a lat/lon with low-to-moderate resolution
JavaScript
7
star
17

pbj

tiny, stupid bitmap image format
JavaScript
6
star
18

cache

An in-memory, promise-backed cache
JavaScript
5
star
19

bounding

calculate bounding areas of points
JavaScript
4
star
20

zqueue

A little redis-backed queue dingus.
JavaScript
4
star
21

cache-helpers

Caching helper functions for Node.JS.
JavaScript
4
star
22

regression

A tiny Javascript toolkit for regression analysis.
JavaScript
4
star
23

shape

spherical geometry library
JavaScript
1
star