mpm.duration

ISO durations from javascript

npm install mpm.duration
12 downloads in the last month

DURATION

Build Status NPM

author mparaiso mparaiso@online.fr

license: MIT

Deals with ISO 8601 durations.

Install

With npm

in package.json

{
    "dependencies":{
        "mpm.duration":"*"
    }
}

Usage

Parse a String , get duration object


    var d1 = duration.parse("P1Y3M10D");
    assert(d.years==1);
    assert(d.months==3);
    assert(d.days==10);

Create a duration object in an object oriented way


    var d2 = new duration.Duration("PT3H10M4.05S");
    assert(d.hours==3);
    assert(d.minutes==10);
    assert(d.seconds==4.05);

Get a ISO duration string from a Duration object


    var d = new duration.Duration();
    d.years=5,d.months=4,d.hours=10;
    assert(d.toString()=="P5Y4MT10H");
npm loves you