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

tzinfo

v0.5.1

Published

parse tzinfo files

Downloads

238

Readme

tzinfo

Build Status Coverage Status

Functions to parse /usr/share/zoneinfo timezone info files. Parses both v1 and v2 format zoneinfo files.

Api

tzinfo.getZoneinfoDirectory( )

Return the auto-detected directory containing the system zoneinfo files.

tzinfo.listZoneinfoFiles( zoneinfoDirectory )

List all the zoneinfo files contained in the named zoneinfo directory. Recursively walks the directory and tests each file found. This is a blocking operation, so call only on program load. The results are small and can be easily cached.

tzinfo.readZoneinfoFile( tzname, cb )

Read the zoneinfo file corresponding to the named timezone. Returns to its callback a Buffer with the file contents, or an Error.

tzinfo.readZoneinfoFileSync( tzname )

Read the zoneinfo file corresponding to the named timezone. Returns a Buffer containing the file contents, or throws an Error.

tzinfo.parseZoneinfo( buf )

Parse the zoneinfo file contained in buf and return it as an object.

Returned object format:

zoneinfo = {
    magic:      // 'TZif'
    version:    // '\0' or '2'

    ttisgmtcnt: // num gmt/local indicators stored in `ttisgmt`
    ttisstdcnt: // num standard/wall indicators stored in `ttisstd`
    leapcnt:    // num leap seconds for which data is stored in `leaps`
    timecnt:    // num transition types stored in `types`
    typecnt:    // num time transition structs stored in `tzinfo`
    charcnt:    // total num chars to store the tz name abbreviations

    ttimes:     // array of `timecnt` transition time timestamps
    types:      // array of `timecnt` tzinfo indices for each time transitioned to
    tzinfo:     // array of `typecnt` tzinfo structs
                //     { idx: , tt_gmtoff: , tt_isdst: , tt_abbrind: }
    abbrevs:    // concatenated tz name abbreviations (asciiz strings totaling charcnt bytes)
    leaps:      // array of `leapcnt` leap second descriptors
    ttisstd:    // array of `ttisstdcnt` transitions of tzinfo were std or wallclock times
    ttisgmt:    // array of `ttisgmtcnt` transitions of tzinfo were UTC or local time
};

tzinfo.findTzinfo( zoneinfo, date [,firstIfTooOld] )

Find in the parsed zoneinfo the index of the tzinfo struct corresponding to the given date. Returns a tzinfo struct or false if the date is before the earliest time transition on record or if date is not valid. If date precedes the first known time transition but firstIfTooOld is truthy, it returns the oldest tzinfo struct. If there are no time transitions defined but there is a tzinfo struct, it returns the tzinfo struct (to always succeed for GMT and UTC).

Tzinfo format:

tzinfo = {
    idx:        // index of this entry in `zoneinfo.tzinfo`
    tt_gmtoff:  // seconds to add to GMT to get localtime
    tt_isdst:   // whether daylight saving is in effect
    tt_abbrind: // byte offset in abbrevs of tz name abbreviation
    abbrev:     // timezone name abbreviation, eg 'EDT'
};

To find the POSIX-style timezone environment variable attributes associated with this tzinfo, look at zoneinfo.ttisstd[tzinfo.idx] and zoneinfo.ttisgmt[tzinfo.idx].

Change Log

  • 0.5.1 - always find GMT zoneinfo
  • 0.5.0 - findTzinfo option to return the oldest known tzinfo struct for very old dates
  • 0.4.2 - more tests, make readStringZ stop on unterminated strings
  • 0.4.1 - npm tag
  • 0.4.0 - listZoneinfoFiles(), getZoneinfoDirectory()
  • 0.3.0 - readZoneinfoFile and readZoneinfoFileSync, findTzinfo
  • 0.2.0 - first published release, with parseZoneinfo

Todo

  • setZoneinfoDirectory to override the auto-detected one

Related Work

  • zoneinfo
  • tzfile(5), zdump(8), zic(8) - unix zoneinfo manpages