From: David Reiman Date: Fri, 2 Oct 2015 17:15:04 +0000 (-0700) Subject: Fix #2645 - invalid dates pre-1970 X-Git-Tag: 2.11.0~41^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6cd13afce307cb7fcfcdbf1414170df71bf67c1d;p=thirdparty%2Fmoment.git Fix #2645 - invalid dates pre-1970 --- diff --git a/src/lib/create/date-from-array.js b/src/lib/create/date-from-array.js index 349eebcc4..6c8053c5e 100644 --- a/src/lib/create/date-from-array.js +++ b/src/lib/create/date-from-array.js @@ -4,7 +4,7 @@ export function createDate (y, m, d, h, M, s, ms) { var date = new Date(y, m, d, h, M, s, ms); //the date constructor doesn't accept years < 1970 - if (y < 1970) { + if (y < 1970 && isFinite(date.getYear()) ) { date.setFullYear(y); } return date; @@ -12,7 +12,7 @@ export function createDate (y, m, d, h, M, s, ms) { export function createUTCDate (y) { var date = new Date(Date.UTC.apply(null, arguments)); - if (y < 1970) { + if (y < 1970 && isFinite(date.getUTCFullYear())) { date.setUTCFullYear(y); } return date; diff --git a/src/test/moment/create.js b/src/test/moment/create.js index e58ca2660..42ec14dff 100644 --- a/src/test/moment/create.js +++ b/src/test/moment/create.js @@ -14,6 +14,11 @@ test('array', function (assert) { assert.equal(+moment(new Date(2010, 1, 14, 15, 25, 50, 125)), +moment([2010, 1, 14, 15, 25, 50, 125]), 'constructing with array === constructing with new Date()'); }); +test('array with invalid arguments', function (assert) { + assert.ok(!moment([2010, null, null]).isValid(), '[2010, null, null]'); + assert.ok(!moment([1945, null, null]).isValid(), '[1945, null, null] (pre-1970)'); +}); + test('array copying', function (assert) { var importantArray = [2009, 11]; moment(importantArray);