From 87c9ae9c58ad4503372a7d171a5335ecd765c9d4 Mon Sep 17 00:00:00 2001 From: Iskren Chernev Date: Mon, 27 Jul 2015 09:39:57 -0700 Subject: [PATCH] Fix regression outlined in #2512 --- src/lib/moment/constructor.js | 2 +- src/test/moment/create.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib/moment/constructor.js b/src/lib/moment/constructor.js index b29b3d7e1..f5f3da0fb 100644 --- a/src/lib/moment/constructor.js +++ b/src/lib/moment/constructor.js @@ -58,7 +58,7 @@ var updateInProgress = false; // Moment prototype object export function Moment(config) { copyConfig(this, config); - this._d = new Date(config._d.getTime()); + this._d = new Date(config._d != null ? config._d.getTime() : NaN); // Prevent infinite loop in case updateOffset creates new moment // objects. if (updateInProgress === false) { diff --git a/src/test/moment/create.js b/src/test/moment/create.js index 202287a4e..9afe7b673 100644 --- a/src/test/moment/create.js +++ b/src/test/moment/create.js @@ -112,6 +112,11 @@ test('undefined', function (assert) { assert.ok(moment().toDate() instanceof Date, 'undefined'); }); +test('iso with bad input', function (assert) { + assert.ok(!moment('a', moment.ISO_8601).isValid(), 'iso parsing with invalid string'); + assert.ok(!moment('a', moment.ISO_8601, true).isValid(), 'iso parsing with invalid string, strict'); +}); + test('iso format 24hrs', function (assert) { assert.equal(moment('2014-01-01T24:00:00.000').format('YYYY-MM-DD[T]HH:mm:ss.SSS'), '2014-01-02T00:00:00.000', 'iso format with 24:00 localtime'); -- 2.47.2