date-duration
Manipulate Date objects with ISO 8601-formatted durations.
Installation
$ npm install date-duration
Usage
import Duration from 'date-duration';
let duration = Duration('PT1H');
let duration = Duration({P: {T: {H: 1}}});
API
Duration(ISOString)
Pass a string in ISO 8601 duration format to create a duration.
duration.addTo(Date)
Add the duration to a Date object and returns the new date. Objects with a .toDate()
(like Moment.js) method are converted to a regular Date object.
duration.subtractFrom(Date)
Subtract the duration from a Date object and returns the new date. Objects with a .toDate()
method are converted to a regular Date object.
duration.add(Duration)
Add durations together returning a new duration which is the sum of both.
duration.toString()
Convert a duration back to a string in ISO 8601 format.