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

tz

v0.1.1

Published

sniff for timezone info using pure JS

Downloads

2,885

Readme

TZ.js

Built for plate; determines (roughly) the timezone name based on a few lovely factors. Adds two prototype methods to Date.

Date.prototype.tzoffset

Get a formated, GMT+0000-style offset string for your locale, based on the result of Date.prototype.getTimezoneOffset.

Date.prototype.tzinfo()

Returns an object with the following information if tzinfo exists for your locale's offset (as returned by Date.prototype.getTimezoneOffset):

    {
          'name'  : 'Human Readable Name of Area'
        , 'loc'   : 'Location of TZ: E.G., North America'
        , 'abbr'  : 'shortname for tz: E.G, CST'
        , 'offset': '(+|-)0XXX'
    }

The TZINFO is collected in tz.json.

How does it work?

Fuzzily. A list of known TZ data is stored in tz.json, keyed by offset (+0000, -0600). The ordering of the list is important. Roughly, the algorithm does the following:

  • Get the offset string from your date.

  • Lookup the list of TZ's corresponding to that offset.

  • Determine whether your timezone has Daylight Savings.

  • Determine the thresholds at which Daylight Savings Time takes effect in your locale, if any.

  • Determine, based on that, whether your locale is in the northern or southern hemisphere. Default to southern hemisphere.

    How does that work?

    If you're in the northern hemisphere, the threshold for "spring forward" will be earlier than "fall back".

    In the south, this is reversed.

  • If your locale is currently in DST, filter the TZ list for names that match /([Dd]aylight|[Ss]ummer)/.

  • If your locale is in the south (or we have no DST info), reverse the list.

  • Return the first time from that list as the TZinfo.

    Why default to the south?

    For countries that have DST, we can easily determine which half of the Earth they're on. For countries that don't, we're forced to guess. However, if we approach from the South, we tend to pick up countries of interest.

Install (in browser)


$ git clone [email protected]:chrisdickinson/tz.js.git
$ cd tz.js
$ make build
$ # now you have tz.js, and if you have uglifyjs or jsmin, you also have tz.min.js

Install (in node)

npm install tz

Run the tests

npm install --dev tz; npm test tz

License

MIT