]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Handling empty string null #184
authorTim Wood <washwithcare@gmail.com>
Thu, 1 Mar 2012 23:44:20 +0000 (11:44 +1200)
committerTim Wood <washwithcare@gmail.com>
Thu, 1 Mar 2012 23:44:20 +0000 (11:44 +1200)
moment.js
test/moment/create.js

index 8ce2705eeb8c793527de1a208e43e50a54396a82..fede61db091dc43347afb939061885ddcc401daa 100644 (file)
--- a/moment.js
+++ b/moment.js
     }
 
     moment = function (input, format) {
-        if (input === null) {
+        if (input === null || input === '') {
             return null;
         }
         var date,
index 4d46f4d2c77f430dae02ce6250d96d1b77d69a9f..7e9afa0400e039fa2da677a211f6f2f90904708d 100644 (file)
@@ -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();
     }
 };