]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Add tests and fix for inconsistent moment.min and moment.max behavior.
authorJoshua Ohlman <codewriterohs@gmail.com>
Fri, 26 Jun 2015 23:44:49 +0000 (18:44 -0500)
committerIskren Chernev <iskren.chernev@gmail.com>
Mon, 13 Jul 2015 00:32:58 +0000 (17:32 -0700)
Fixes #2362

src/lib/moment/min-max.js
src/test/moment/min_max.js

index c4a88d24e0762979624dd1299f40ca9600cba6b4..912cbfe71902c4dc3e7751a9334f5e4d2167a4d3 100644 (file)
@@ -33,7 +33,7 @@ function pickBy(fn, moments) {
     }
     res = moments[0];
     for (i = 1; i < moments.length; ++i) {
-        if (moments[i][fn](res)) {
+        if (!moments[i].isValid() || moments[i][fn](res)) {
             res = moments[i];
         }
     }
index 62054d6d681bc79d3eebf7452975a8188228665d..0db251d44a0f342fa5ea74faea99f4b3606ed505 100644 (file)
@@ -6,7 +6,8 @@ module('min max');
 test('min', function (assert) {
     var now = moment(),
         future = now.clone().add(1, 'month'),
-        past = now.clone().subtract(1, 'month');
+        past = now.clone().subtract(1, 'month'),
+        invalid = moment.invalid();
 
     assert.equal(moment.min(now, future, past), past, 'min(now, future, past)');
     assert.equal(moment.min(future, now, past), past, 'min(future, now, past)');
@@ -19,12 +20,16 @@ test('min', function (assert) {
     assert.equal(moment.min([now, future, past]), past, 'min([now, future, past])');
     assert.equal(moment.min([now, past]), past, 'min(now, past)');
     assert.equal(moment.min([now]), now, 'min(now)');
+
+    assert.equal(moment.min([now, invalid]), invalid, 'min(now, invalid)');
+    assert.equal(moment.min([invalid, now]), invalid, 'min(invalid, now)');
 });
 
 test('max', function (assert) {
     var now = moment(),
         future = now.clone().add(1, 'month'),
-        past = now.clone().subtract(1, 'month');
+        past = now.clone().subtract(1, 'month'),
+        invalid = moment.invalid();
 
     assert.equal(moment.max(now, future, past), future, 'max(now, future, past)');
     assert.equal(moment.max(future, now, past), future, 'max(future, now, past)');
@@ -37,4 +42,7 @@ test('max', function (assert) {
     assert.equal(moment.max([now, future, past]), future, 'max([now, future, past])');
     assert.equal(moment.max([now, past]), now, 'max(now, past)');
     assert.equal(moment.max([now]), now, 'max(now)');
+
+    assert.equal(moment.max([now, invalid]), invalid, 'max(now, invalid)');
+    assert.equal(moment.max([invalid, now]), invalid, 'max(invalid, now)');
 });