duratiform
Utility to separate into parts and to format time duration in milliseconds.
duratiform; // { day: 1428, hour: 21, minute: 33, second: 9 }duratiform; // 07:36
See additional examples below.
Installation
Node
npm install duratiform
Bower
bower install duratiform
AMD, <script>
Use dist/duratiform.js
or dist/duratiform.min.js
(minified version).
Usage
Node
var duratiform = ;
AMD
;
Bower, <script>
<!-- Use bower_components/duratiform/dist/duratiform.js if the library was installed by Bower -->
Examples
var nDuration = 123456789000;console; // { week: 204, day: 0, hour: 21, minute: 33, second: 9 }console; // 204 weeks 0 days 21 hours 33 minutes 9 secondsconsole; // { day: 1428, hour: 21, minute: 33, second: 9 }console; // 1428 days 21 hours 33 minutes 9 seconds console; // { day: 1, hour: 9, minute: 23, second: 4 }console; // { day: 1, day2: "01", hour: 9, hour2: "09", minute: 23, minute2: "23", second: 4, second2: "04" }console; // { hour: 33, minute: 23, second: 4 } console; // 1:16:07console; // 07:36console; // empty string console; // Duration: 1 hr 16 min 07 secconsole; // Duration: 7 min 36 secconsole; // Duration: 6 sec
See test/duratiform.js
for additional examples.
API
divide(nDuration: number, [nPartQty: number], [bAddStrings: boolean]): object
Separate time duration into parts.
format(nDuration: number, [sFormat: string]): string
Convert time duration into string.
See docs
for details.
License
MIT