From: Christopher Brown Date: Fri, 31 May 2013 21:21:55 +0000 (-0500) Subject: Add duration.add() and duration.subtract() methods. X-Git-Tag: 2.1.0~21^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e9e6c4201768446406984613ca19d39c376007fc;p=thirdparty%2Fmoment.git Add duration.add() and duration.subtract() methods. --- diff --git a/moment.js b/moment.js index 257995255..5247ab5a6 100644 --- a/moment.js +++ b/moment.js @@ -1504,6 +1504,27 @@ return this.lang().postformat(output); }, + add : function (input, val) { + // supports only 2.0-style add(1, 's') or add(moment) + var dur = moment.duration(input, val); + + this._milliseconds += dur._milliseconds; + this._days += dur._days; + this._months += dur._months; + + return this; + }, + + subtract : function (input, val) { + var dur = moment.duration(input, val); + + this._milliseconds -= dur._milliseconds; + this._days -= dur._days; + this._months -= dur._months; + + return this; + }, + get : function (units) { units = normalizeUnits(units); return this[units.toLowerCase() + 's']();