0.0.1 • Published 10 years ago
chronos.js v0.0.1
Chronos.js is a library for interpreting duration into strings
Pass it milliseconds as an integer and get something like 2:08:45
or 2 hours and 8 minutes
Installation
Via node.js
$ npm install chronos.js
Via bower
$ bower install chronos.js
Usage
Pass to Chronos a duration in milliseconds.
new Chronos(34000)
Then use one of the methods below:
.toHHMMSS()
Will convert the duration into a string with the format hh:mm:ss
new Chronos(34000).toHHMMSS() // "0:34"
new Chronos(249000).toHHMMSS() // "4:09"
new Chronos(252000).toHHMMSS() // "4:12"
new Chronos(1200000).toHHMMSS() // "20:00"
new Chronos(7725000).toHHMMSS() // "2:08:45"
new Chronos(43200000).toHHMMSS() // "12:00:00"
Specifying a delimiter
By default, the delimiter will be a :
sign.
You can pass another delimiter as an option:
new Chronos(43200000).toHHMMSS({delimiter: "."}) // "12.00.00"
.toHourMin()
Will convert the duration into a string with the format hh hours and mm minutes
(or ss seconds
if there's only seconds)
new Chronos(34000).toHourMin() // "34 seconds"
new Chronos(249000).toHourMin() // "4 minutes"
new Chronos(252000).toHourMin() // "4 minutes"
new Chronos(1200000).toHourMin() // "20 minutes"
new Chronos(7725000).toHourMin() // "2 hours and 8 minutes"
new Chronos(43200000).toHourMin() // "12 hours"
Contribute
Comments, bug reports, and pull requests are all welcome!
To run the tests:
npm test
Thanks
0.0.1
10 years ago