Permalink
Browse files

Handling empty string null #184

  • Loading branch information...
timrwood committed Mar 1, 2012
1 parent a701fc3 commit 83f92a16bdf30d464a9046b677129aef67cf0658
Showing with 9 additions and 1 deletion.
  1. +1 −1 moment.js
  2. +8 −0 test/moment/create.js
View
@@ -379,7 +379,7 @@
}
moment = function (input, format) {
- if (input === null) {
+ if (input === null || input === '') {
return null;
}
var date,
View
@@ -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();
}
};

0 comments on commit 83f92a1

Please sign in to comment.