milliseconds-to-iso-8601-duration

Convert millisecond durations to ISO 8601


Keywords
duration, iso-8601
License
MIT
Install
bower install milliseconds-to-iso-8601-duration

Documentation

milliseconds-to-iso-8601-duration is a tiny library to convert millisecond durations to ISO 8601 durations. The existing xsdurations is usually sufficient for consuming ISO 8601 durations, so use that if you have a duration and want to add it to a date. Here we are only concerned with producing durations from dates. Instances of Date support subtraction returning millisecond offsets, so you can use this library for things like:

var a = new Date(2015, 5, 21, 14, 11);
var b = new Date(2015, 5, 22, 16, 45);
var duration = millisecondsToISO8601Duration.iso8601duration(b - a);

to set duration to "P1DT2H34M".

Tests

The test suite uses QUnit via Grunt and grunt-contrib-qunit. Install the tools with npm:

$ npm install -g grunt-cli
$ npm install

And then run the tests with:

$ grunt