From: Tim Wood Date: Thu, 1 Mar 2012 23:44:20 +0000 (+1200) Subject: Handling empty string null #184 X-Git-Tag: 1.5.0~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=83f92a16bdf30d464a9046b677129aef67cf0658;p=thirdparty%2Fmoment.git Handling empty string null #184 --- diff --git a/moment.js b/moment.js index 8ce2705ee..fede61db0 100644 --- a/moment.js +++ b/moment.js @@ -379,7 +379,7 @@ } moment = function (input, format) { - if (input === null) { + if (input === null || input === '') { return null; } var date, diff --git a/test/moment/create.js b/test/moment/create.js index 4d46f4d2c..7e9afa040 100644 --- a/test/moment/create.js +++ b/test/moment/create.js @@ -179,5 +179,13 @@ exports.create = { test.equal(moment(formats[i][0]).format('YYYY-MM-DDTHH:mm:ssZ'), formats[i][1], "moment should be able to parse ISO " + formats[i][0]); } test.done(); + }, + + "null" : function(test) { + test.expect(3); + test.equal(moment(''), null, "Calling moment('')"); + test.equal(moment(null), null, "Calling moment(null)"); + test.equal(moment('', 'YYYY-MM-DD'), null, "Calling moment('', 'YYYY-MM-DD')"); + test.done(); } };