node package manager
Loosely couple your services. Use Orgs to version and reuse your code. Create a free org »



ISO 8601 duration support for Moment.js.


Parsing an ISO 8601 duration string:

var oneWeek = moment.isoDuration('P1W');
var twoDaysThreeHours = moment.isoDuration('P2DT3H');
var fourSeconds = moment.isoDuration('PT4S');
var allMixed = moment.isoDuration('P1Y2M3DT4H5M6S');

The ISO spec for durations doesn't define a millisecond unit, but I consider it useful so added it anyway under the Z unit.

var twentyMilliseconds = moment.isoDuration('PT20Z');

There's also a helper method to get a duration value in ISO format.

var delay = moment.duration(100);
var isoString = delay.toISOString(duration); // PT100Z 


moment-duration is freely distributable under the terms of the MIT license.