Skip to content

nbroslawsky/timestr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

timestr

A simple module for interpreting time duration strings.

Build Status browser support

Installation

npm install timestr

Useage

Create a timestr object from a time duration string and use as needed:

var timestr = require('timestr'),
    time = timestr('5 weeks');

time.toMilliseconds(); // => 3024000000
time.toSeconds(); // => 3024000
time.toMinutes(); // => 50400
time.toHours(); // => 840
time.toDays(); // => 35
time.toWeeks() // => 5;

Formats

You can create a timestr object from most common formats:

var timestr = require('timestr');

// without units, values are treated as ms
timestr(1000);
timestr('1000');

// milliseconds
timestr('1ms');
timestr('1 millisecond');
timestr('2 milliseconds');

// seconds
timestr('1s');
timestr('1 sec');
timestr('1 secs');
timestr('1 second');
timestr('2 seconds');

// minutes
timestr('1m');
timestr('1 min');
timestr('1 mins');
timestr('1 minute');
timestr('2 minutes');

// hours
timestr('1h');
timestr('1 hr');
timestr('1 hrs');
timestr('1 hour');
timestr('2 hours');

// days
timestr('1d');
timestr('1 day');
timestr('2 days');

// weeks
timestr('1w');
timestr('1 wk');
timestr('1 wks');
timestr('1 week');
timestr('2 weeks');

About

A simple module for interpreting time duration strings

Resources

License

Stars

Watchers

Forks

Packages

No packages published