From: Joshua Ohlman Date: Fri, 26 Jun 2015 23:44:49 +0000 (-0500) Subject: Add tests and fix for inconsistent moment.min and moment.max behavior. X-Git-Tag: 2.10.5~23^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b10cce0b8f31c30f31b77130b64852a78729f26;p=thirdparty%2Fmoment.git Add tests and fix for inconsistent moment.min and moment.max behavior. Fixes #2362 --- diff --git a/src/lib/moment/min-max.js b/src/lib/moment/min-max.js index c4a88d24e..912cbfe71 100644 --- a/src/lib/moment/min-max.js +++ b/src/lib/moment/min-max.js @@ -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]; } } diff --git a/src/test/moment/min_max.js b/src/test/moment/min_max.js index 62054d6d6..0db251d44 100644 --- a/src/test/moment/min_max.js +++ b/src/test/moment/min_max.js @@ -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)'); });