Natty Precise Maverick

    spacetime-geo

    1.4.1 • Public • Published
    lat/long ←→ timezone
    npm install spacetime-geo

    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.

    1091

    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

    Keywords

    Install

    npm i spacetime-geo

    DownloadsWeekly Downloads

    116

    Version

    1.4.1

    License

    MIT

    Unpacked Size

    395 kB

    Total Files

    16

    Last publish

    Collaborators

    • spencermountain