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

time-stamps

v1.0.0

Published

Converts a large variety of timestamp formats to a JavaScript Date object.

Downloads

21

Readme

time-stamps

Coveralls Status Build Status

This module converts a variety of timestamp formats to a standard JavaScript Date object. It accepts, as input, the formats listed below. It exports its functions in both camelCase and snake case formats. In other words, it would have both unixToDate() and unix_to_date() available pointing to the same function, for example.

  • JavaScript timestamp

    This is the standard milliseconds since the UNIX epoch (1970-01-01) that you would get from +new Date().

  • *NIX timestamp

    A standard *nix timestamp in sedconds starting at the usual epoch, same as JavaScript timestamp in seconds, equivalent to +new Date() / 1000.

  • Microsoft FILETIME

    This is a standard Microsoft FILETIME timestamp, measured in 100 nanosecond intervals since 1601-01-01.

  • NTP timestamp

    The time carried by the NTP protocol in seconds since 1900-01-01 along with a fractional second in microsecond intervals.

  • NTP network timestamp

    Essentiall same as above except it accepts a Uint8Array of raw input from the network packet. It would be 8 bytes in network order (high endian).

  • HFS+ timestamp

    This takes an HFS+ timestamp measured in seconds since 1904-01-01.

  • OLE Automation timestamp

    Sometimes also called a Microsoft timestamp. It's a fractional value counting seconds since 1899-01-01.

  • LDAP timestamp

    This is essentially the same as the FILETIME but will return null for marginal values.

  • DOS timestamp

    A bit packed 32-bit value encoding a time and date with a 2 second level of precision.

Also included is a function that attempts to guess the timestamp format. This can be helpful if you may receive both JavaScript and UNIX timestamps. It may guess wrong as it doesn't try anything overly extravagant to determine the timestamp type. I use successfully to distinguish between JavaScript and UNIX timestamps that are not decades removed from our current time.

Usage

const
    { 
        js_to_date, 
        unix_to_date, 
        filetime_to_date, 
        ntp_to_date, 
        network_ntp_to_date, 
        hfs_to_date, 
        ole_to_date,
        ldap_to_date,
        dos_to_date,
        to_date
    } = require( 'time-stamps' ),
    
    someTimestamp = +new Date( '2016-09-22T19:22:14Z' ),
    someUnixTimestamp = someTimestamp / 1000;

let ts1 = js_to_date( someTimestamp ),
    ts2 = unix_to_date( someUnixTimestamp );

assert( String( ts1 ) === String( ts2 ) );

// or

const 
    ts = require( 'time-stamps' );

let tsa = ts.js_to_date( someTimestamp ),
    tsb = ts.unix_to_date( someUnixTimestamp );

assert( String( tsa ) === String( tsb ) );