]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Fix moment issue #3997 4063/head
authorAsh Searle <ash@hexmen.com>
Tue, 11 Jul 2017 18:46:43 +0000 (19:46 +0100)
committerAsh Searle <ash@hexmen.com>
Tue, 11 Jul 2017 18:46:43 +0000 (19:46 +0100)
src/lib/moment/add-subtract.js
src/test/moment/duration.js

index b9e86a69d2a86c3e4e041c1c98874e99e50d9108..e758b5d46609b18ead3d18e52aeec2a75c3a5ba8 100644 (file)
@@ -36,14 +36,14 @@ export function addSubtract (mom, duration, isAdding, updateOffset) {
 
     updateOffset = updateOffset == null ? true : updateOffset;
 
-    if (milliseconds) {
-        mom._d.setTime(mom._d.valueOf() + milliseconds * isAdding);
+    if (months) {
+        setMonth(mom, get(mom, 'Month') + months * isAdding);
     }
     if (days) {
         set(mom, 'Date', get(mom, 'Date') + days * isAdding);
     }
-    if (months) {
-        setMonth(mom, get(mom, 'Month') + months * isAdding);
+    if (milliseconds) {
+        mom._d.setTime(mom._d.valueOf() + milliseconds * isAdding);
     }
     if (updateOffset) {
         hooks.updateOffset(mom, days || months);
index c7e0ea377bf5b36353808305bb524e039a04df2e..624d77787e5e48016dac1c387d46abbb64694b42 100644 (file)
@@ -611,6 +611,13 @@ test('add', function (assert) {
     assert.equal(d.add({h: 23, m: 59})._milliseconds, 23 * 60 * 60 * 1000 + 59 * 60 * 1000 + 10000, 'Add hour:minute');
 });
 
+test('add to moment', function (assert) {
+    var d = moment.duration({months: 1, seconds: -1});
+    var m = moment('2017-03-01').add(d);
+    assert.equal(m.month(), 2, 'Adds months before time');
+    assert.equal(m.date(), 31, 'Adds time after months');
+});
+
 test('add and bubble', function (assert) {
     var d;