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

timestamp-grabber

v0.2.1

Published

Convert a very wide variety of human readable date/time formats to unix timestamp in millis. Supports all major timezones thanks to timezonejs

Downloads

24

Readme

timestamp-grabber

Have you been searching the NodeJS scene everywhere for a simple date parser tool that can handle timezones too? Search no more, I present you the timestamp-grabber. There are tons of modules to do whatever you want with timestamps, but to get to the timestamp timezone aware has been lacking. Convert a very wide variety of human readable date/time formats to unix timestamp in millis. Supports all major timezones thanks to the Timezone module.

The code is very fogiving in terms of pattern definition. The code is easily extendable for even more cases.

With version 0.1 added timestamp to array too

  • date=ts.toArray(1423435171000,"Asia/Shanghai")
  • deq(date,[ 2015, 2, 9, 6, 39, 31, 0])

how it works

Here is how it works. There are 2 public methods as you can see in the following tests. You will most likely use parse, that gives you the unix timestamp in millis.

  • ts = require("timestamp-grabber")
  • console.log(ts.parse("1/22/14 10:23:01.001 PM *", "M D Y HH:mm:ss.fff tt", "America/New_York"))
  • ->1390447381001

Note that the number of token letters is optional, you can write YYYY, YY, Y, it will recognize the 2 digit or 4 digit year anyways. Currently there is no "strict mode" that throws error if digit counts do not match. The only exception now from this rule is MMM which denotes the month when using 3 letter english month names instead of digits.

##Tests

eq(ts.parse("Tue May 08 20:24:06 +0000 2014","w MMM DD HH:mm:ss +oooo YYYY","Etc/GMT-11"),ts.parse("Tue May 08 20:24:06 -0011 2014","w MMM DD HH:mm:ss +oooo YYYY"))

eq(ts.parse("1/22/14 10:23:01.001 PM *", "M D Y HH:mm:ss.fff tt", "Europe/Kiev"),ts.parse("1/22/14 10:23:01.001 PM *", "M D Y HH:mm:ss.fff tt", "Europe/Berlin")-1000*60*60)

eq(ts.parse("1/22/14 10:23:01.001 PM *", "M D Y HH:mm:ss.fff tt", "America/New_York")+3*1000*60*60,ts.parse("1/22/14 10:23:01.001 PM *", "M D Y HH:mm:ss.fff tt", "America/Los_Angeles"))

eq(ts.parse("1/22/14 10:23:01.001 PM *", "M D Y HH:mm:ss.fff tt", "Europe/Budapest")+9*1000*60*60,ts.parse("1/22/14 10:23:01.001 PM *", "M D Y HH:mm:ss.fff tt", "America/Los_Angeles"))

eq(ts.parse("Feb 19, 2014 at 01:52", "MMM DD, YYYY at HH:mm", "Etc/Greenwich"),1392774720000)

#####result=ts.parseDate("2014-05-08 20:24:06.400","YYYY-MM-DD HH:mm:ss.fff",false)

  • eq(result.Y,2014)
  • eq(result.M,5)
  • eq(result.D,8)
  • eq(result.H,20)
  • eq(result.m,24)
  • eq(result.s,6)
  • eq(result.f,400)

#####result = ts.parseDate("1994/01/02 11:03:04.6 PM", "YYYY MM DD HH:mm:ss.f tt") #T11:03:04.666 PM

  • eq(result.Y,1994)
  • eq(result.M,1)
  • eq(result.D,2)
  • eq(result.H,23)
  • eq(result.m,3)
  • eq(result.s,4)
  • eq(result.f,600)

#####result=ts.parseDate("1994-1-2T11:3:4.600") #T11:03:04.666 PM

  • eq(result.Y,1994)
  • eq(result.t,undefined)

#####result=ts.parseDate("1994-1-2 11:03 AM") #T11:03:04.666 PM

  • eq(result.Y,1994)
  • eq(result.H,11)
  • eq(result.s,undefined)
  • eq(result.f,undefined)

#####result =ts.parseDate("1/15/14 10:23 PM *", "M D Y H:m tt") #T11:03:04.666 PM

  • eq(result.Y,2014)
  • eq(result.M,1)
  • eq(result.D,15)
  • eq(result.H,22)
  • eq(result.m,23)

#####result=ts.parseDate("20140906 01:59:14.400","YYYYMMDD HH:mm:ss.fff")

  • eq(result.Y,2014)
  • eq(result.M,9)
  • eq(result.D,6)
  • eq(result.H,1)
  • eq(result.m,59)
  • eq(result.s,14)
  • eq(result.f,400)

License

  • license.txt