]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Add duration.add() and duration.subtract() methods.
authorChristopher Brown <io@henrian.com>
Fri, 31 May 2013 21:21:55 +0000 (16:21 -0500)
committerChristopher Brown <io@henrian.com>
Fri, 31 May 2013 21:21:55 +0000 (16:21 -0500)
moment.js

index 2579952556b198d99a532ebcde65c222930ba8ea..5247ab5a67925afab0e47cf3bee4821ab9bf85f6 100644 (file)
--- a/moment.js
+++ b/moment.js
             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']();