if (!this.asSeconds()) {
// this is the same as C#'s (Noda) and python (isodate)...
// but not other JS (goog.date)
- return 'PT0D';
+ return 'P0D';
}
return (this.asSeconds() < 0 ? '-' : '') +
},
"serialization to ISO 8601 duration strings" : function (test) {
- test.expect(5);
+ test.expect(6);
test.equal(moment.duration({y: 1, M: 2, d: 3, h: 4, m: 5, s: 6}).toIsoString(), "P1Y2M3DT4H5M6S", "all fields");
test.equal(moment.duration({M: -1}).toIsoString(), "-P1M", "one month ago");
test.equal(moment.duration({m: -1}).toIsoString(), "-PT1M", "one minute ago");
test.equal(moment.duration({s: -0.5}).toIsoString(), "-PT0.5S", "one half second ago");
test.equal(moment.duration({y: -0.5, M: 1}).toIsoString(), "-P5M", "a month after half a year ago");
+ test.equal(moment.duration({}).toIsoString(), "P0D", "zero duration");
test.done();
},