duration-converter
TypeScript icon, indicating that this package has built-in type declarations

1.3.6 • Public • Published

duration

Build Status Coverage Status npm dependencies Status devDependencies Status Downloads/week

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.

Dependents (1)

Package Sidebar

Install

npm i duration-converter

Weekly Downloads

586

Version

1.3.6

License

ISC

Unpacked Size

17.4 kB

Total Files

6

Last publish

Collaborators

  • gnarr