moment-duration

0.0.6 • Public • Published

moment-duration

ISO 8601 duration support for Moment.js.

Examples

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

License

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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.6
    508
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.6
    508
  • 0.0.5
    0

Package Sidebar

Install

npm i moment-duration

Weekly Downloads

461

Version

0.0.6

License

MIT

Last publish

Collaborators

  • lufo