var s = seconds ? seconds.toFixed(3).replace(/\.?0+$/, '') : '';
var total = this.asSeconds();
- var totalSign = total < 0 ? '-' : '';
- var ymSign = sign(total) === sign(this._months) ? '' : '-';
- var daysSign = sign(total) === sign(this._days) ? '' : '-';
- var hmsSign = sign(total) === sign(this._milliseconds) ? '' : '-';
-
if (!total) {
// this is the same as C#'s (Noda) and python (isodate)...
// but not other JS (goog.date)
return 'P0D';
}
+ var totalSign = total < 0 ? '-' : '';
+ var ymSign = sign(this._months) != sign(total) ? '-' : '';
+ var daysSign = sign(this._days) != sign(total) ? '-' : '';
+ var hmsSign = sign(this._milliseconds) != sign(total) ? '-' : '';
+
return totalSign + 'P' +
(Y ? ymSign + Y + 'Y' : '') +
(M ? ymSign + M + 'M' : '') +
assert.equal(moment.duration({m: -1}).toISOString(), '-PT1M', 'one minute ago');
assert.equal(moment.duration({s: -0.5}).toISOString(), '-PT0.5S', 'one half second ago');
assert.equal(moment.duration({y: -1, M: 1}).toISOString(), '-P11M', 'a month after a year ago');
+ assert.equal(moment.duration({y: -1, h: 1}).toISOString(), '-P1YT-1H', 'an hour after a year ago');
+ assert.equal(moment.duration({y: -1, h: 1, m: -1}).toISOString(), '-P1YT-59M', '59 minutes after a year ago');
+ assert.equal(moment.duration({y: -1, h: 1, s: -1}).toISOString(), '-P1YT-59M-59S', '59 minutes 59 seconds after a year ago');
+ assert.equal(moment.duration({y: -1, h: -1, s: 1}).toISOString(), '-P1YT59M59S', '59 minutes 59 seconds after a year ago');
+ assert.equal(moment.duration({y: -1, d: 2}).toISOString(), '-P1Y-2D', '1 year less 2 days ago');
assert.equal(moment.duration({M: +1}).toISOString(), 'P1M', 'one month ago');
assert.equal(moment.duration({m: +1}).toISOString(), 'PT1M', 'one minute ago');
assert.equal(moment.duration({s: +0.5}).toISOString(), 'PT0.5S', 'one half second ago');