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

@flat/time

v0.0.6

Published

date-agnostic time parsing for node and the browser (forked from time-js package)

Downloads

5

Readme

@flat/time

Build Status

Parses time input with no relation to dates, with the option to convert to the next immediate corresponding Date.

Built to solve this problem. Forked from zackdever/time.

$ npm install @flat/time
var t = Time('2p');
t.hours();             // 2
t.militaryHours();     // 14
t.minutes();           // 0
t.period();            // 'pm'
t.toString();          // '2:00 pm'
t.nextDate();          // Sep 10 2:00 (assuming it is 1 o'clock Sep 10)
t.format('hh:mm AM')   // '02:00 PM'
t.isValid();           // true
Time.isValid('99:12'); // false
// you get the idea, or see below for more ideas

Examples

Some example uses can be viewed in examples.html.

Parses strings such as "8:20" into a Date-less Time.

new Time('1')    // 1:00
new Time('13')   // 1:00 pm
new Time('1:23') // 1:23

If you fancy it, you can use safely drop the 'new'.

Time('1.23') // 1:23
Time('123')  // 1:23

am/pm can optionally be specified.

Time('8:30 pm') // 8:30 pm
Time('3p')      // 3:00 pm
Time('3 A.M.')  // 3:00 am

Converts Time into the next corresponding JavaScript Date.

// assume it's 3:15 pm Aug 10
Time('415').nextDate()  // 4:15 pm Aug 10
Time('2').nextDate()    // 2:00 am Aug 11
Time('2 pm').nextDate() // 2:00 pm Aug 11

Does validation statically...

Time.isValid('8:00')  // true
Time.isValid('12:60') // false
Time.isValid('13:23') // true

... or after construction.

Time('1').isValid()      // true
Time('12.0').isValid()   // false
Time('12:202').isValid() // false

There's basic formatting

Time('2:30p').format('hh:mm A'); // '02:30 P'
Time('2:30p').format('HH:mm');   // '14:30'
Time('12 am').format('h: p');    // '12 a'
Time('220 a').format('h: p');    // '2:20 a'
Time('7').format('h: p');        // '7'

Accepts numbers too.

Time(1).isValid() // true

Military (24-hour) time support

Time('13').format('hh:mm AM');   // '01:00 PM'
Time('2:30p').format('HH:mm');   // '14:30'
Time('14:30').format('h:mm AM'); // '2:30 PM'
Time('0000').format('h:mm AM');  // '12:00 AM'
Time('2400').isValid();          // false (contrary to ISO8601)

ISO8601 time component (without seconds) support

Time('12:00 am').toISOString();  // '00:00'
Time('12:00 pm').toISOString();  // '12:00'
Time('11:00 pm').toISOString();  // '23:00'

Test

$ npm test