Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tz

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tz

sniff for timezone info using pure JS

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
769
increased by30.12%
Maintainers
1
Weekly downloads
 
Created
Source

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)

Pending.

Install (in node)

npm install tz

Run the tests

npm install --dev tz; npm test tz

License

MIT

Keywords

FAQs

Package last updated on 17 Jan 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc