npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

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.

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