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-funcs

v0.1.0

Published

A very limited subset of time functions I use every day

Downloads

5

Readme

time-funcs

A very limited subset of time functions I use every day

Install

npm i time-funcs

Package on npm

API

days(data)

Convert a data time object to a duration in days

const days = require('time-funcs/days')

// 2
days({hours:48})

// 0.5
days({hours:12})

// 0.041666666666666664
days({hours:1})

// 0.041666666666666664
days({minutes:60})

// 0.999999988425926
days({hours:23, minutes:59, seconds:59, milliseconds:999})

hours(data)

Convert a data time object to a duration in hours

const hours = require('time-funcs/hours')

// 24
hours({days:1})

// 2
hours({minutes:120})

// 0.5
hours({minutes:30})

// 0.9999997222222222
hours({minutes:59, seconds:59, milliseconds:999})

minutes(data)

Convert a data time object to a duration in minutes

const minutes = require('time-funcs/minutes')

// 120
minutes({hours:2})

// 2
minutes({seconds:120})

// 0.5
minutes({seconds:30})

// 0.9999833333333333
minutes({seconds:59, milliseconds:999})

seconds(data)

Convert a data time object to a duration in seconds

const seconds = require('time-funcs/seconds')

// 120
seconds({minutes:2})

// 1
seconds({milliseconds:1000})

// 0.5
seconds({seconds:30})

// 60.999
seconds({minutes:1, milliseconds:999})

milliseconds(data)

Convert a data time object to a duration in milliseconds

const milliseconds = require('time-funcs/milliseconds')

// 60000
milliseconds({minutes:1})

// 1000
milliseconds({seconds:1})

// 61001
milliseconds({minutes:1, seconds:1, milliseconds:1})

duration(data, [unit])

Convert a duration into a time objet

| Argument | Action | | :------ | :------- | | data | the duration | | unit | optional unit, default to ms |

Valid unit values

| Unit | Action | | :------ | :------- | | ms | data as milliseconds | | s | data as seconds | | m | data as minutes | | h | data as hours | | d | data as days |

const duration = require('time-funcs/duration')

// {seconds: 2}
duration(2000, 'ms')

// {minutes: 1}
duration(60000, 'ms')

// {seconds: 59, milliseconds: 900}
duration(59.9, 's')

// {minutes: 1, milliseconds: 1}
duration(60.001, 's')

// {hours: 1}
duration(3600, 's')

// {days: 1}
duration(86400, 's')

// {hours: 1, minutes: 6}
duration(1.1, 'h')

timestamp(pattern, [date])

Timestamp formated by a string pattern and some special chars

| Argument | Action | | :------ | :------- | | pattern | the string pattern, default to H:M:S.L | | date | optional date, default to now |

Pattern special chars

| Char | Action | | :------ | :------- | | Y | the year with the century | | y | the year without the century (00-99) | | z | the year without the century, padded with a leading space for single digit values (1-9) | | O | the month, padded to 2 digits (01-12) | | o | the month | | p | the month, padded with a leading space for single digit values (1-9) | | D | day of the month, padded to 2 digits (01-31) | | d | day of the month | | e | day of the month, padded with a leading space for single digit values (1-9) | | H | the hour (24-hour clock), padded to 2 digits (00-23) | | h | the hour (24-hour clock) | | i | the hour (24-hour clock), padded with a leading space for single digit values (0-9) | | M | the minute, padded to 2 digits (00-59) | | m | the minute | | n | the minute, padded with a leading space for single digit values (0-9) | | S | the second, padded to 2 digits (00-60) | | s | the second | | t | the second, padded with a leading space for single digit values (0-9) | | L | the milliseconds, padded to 3 digits | | l | the milliseconds (only the first digit) |

const timestamp = require('time-funcs/timestamp')

// 09 nov 2014 09:27:01.002
var d = new Date(2014, 10, 9, 9, 27, 1, 20)

// [2014-11-09]
timestamp('[Y-O-D]', d)

// 09/11/2014
timestamp('D/O/Y', d)

// 09:27:01.020
timestamp(null, d)

durastamp(seconds, [decimal], [pad])

Convert a duration in seconds in a formated like a video player timestamp

| Argument | Action | | :------ | :------- | | seconds | the duration to format | | decimal | optional decimal count of milliseconds, default to 0. 0 to 3 accepted | | pad | optional 0 padding for leading hours of minutes, default to false |

const durastamp = require('time-funcs/durastamp')

// 0:01
durastamp(1)

// 1:01
durastamp(61)

// 10:00
durastamp(600)

// 1:00:00
durastamp(3600)

// 1:00.2
durastamp(60.234, 1)

// 1:00.234
durastamp(60.234, 3)

// 01:01
durastamp(61, 0, true)

License

MIT