spacetime-geo
v1.4.1
Published
determine a timezone from a lat/lng
Downloads
862
Readme
spacetime plugin for determining a timezone based on a point on the earth, and vice-versa.
this is really just a wrapper of tz-lookup by dark-sky - based on Evan Siroky's awesome boundary-builder work.
import spacetime from './src/index'
import geo from 'spacetime-geo'
//apply the plugin
spacetime.extend(geo)
//set a specific time somewhere
let s = spacetime('June 4 2018', 'Canada/Eastern').time('3:37pm')
//where is this timezone? (approx)
s.point()
//{ lat: 43.65, lng: -79.38 }
//go to a specific point (near paris)
s.in([48.7235, 1.9931])
s.timezone().name
//Europe/Paris
s.time()
//9:37pm
in the browser: 111kb
(uncompressed)
<script src="https://unpkg.com/spacetime"></script>
<script src="https://unpkg.com/spacetime-geo"></script>
<script>
spacetime.extend(spacetimeGeo)
var d = spacetime.now()
//in the suburbs of São Paulo..
d.in({lat:-23.7201, lon:-46.9543})
console.log(d.time())
</script>
spacetime-geo accepts other formats of geolocation too:
spacetime.now().in({lat:42.7235, lon:-73.6931})
spacetime.now().in('48.7235, 1.9931')
Caveats - .in()
timezone boundaries are very, very detailed things. In order to keep this library small, we've simplified the paths. This may produce some off-by-one errors, close to the boundaries, especially for jagged coasts, or complex political boundaries.
You can always produce a more-detailed, and larger (<=130mb!) dataset using Evan Siroky's script.
Caveats - .point()
I made-up an arbitrary point for each IANA timezone using the most-populous city in each timezone, and not any fancy centroid-math. This is all pretty-subjective stuff, especially for timezones like Etc/GMT-9
. It should be fine for, centering a map, but probably not for doing air-strikes.
See also
MIT