duration-converter
v1.3.6
Published
a small utility for converting between duration units.
Downloads
3,586
Maintainers
Readme
duration
A small utility for converting between duration units. E.g '7 Weeks' to Micro Seconds.
Installation
Node.js
$ npm install duration-converter
Example usage:
const { Duration } = require('duration-converter');
const sevenWeeks = new Duration('7 Weeks');
const milliseconds = sevenWeeks.MilliSeconds;
const threeDays = Duration.fromDays(3);
const hours = threeDays.Hours;
// will print out "4 days"
console.log(Duration.fromSeconds(345600).toString());
const a = new Date(2019, 3, 14);
const b = new Date(2019, 3, 15);
const betweenDates = Duration.between(a, b);
// will print 86400000
console.log(betweenDates.MilliSeconds);
Warning!
Note that a year is always interpreted as being 365 days. There are no leap year calculations so going between units that cross the year "boundaries" will result in a small rounding error.