From: Brad Dunbar Date: Mon, 24 Oct 2011 22:17:02 +0000 (-0400) Subject: setters - falsey values X-Git-Tag: 1.1.0~6^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F31%2Fhead;p=thirdparty%2Fmoment.git setters - falsey values --- diff --git a/moment.js b/moment.js index e92398bdd..8aa9e83da 100644 --- a/moment.js +++ b/moment.js @@ -442,7 +442,7 @@ // helper for adding shortcuts function makeShortcut(name, key) { moment.fn[name] = function (input) { - if (input) { + if (input != null) { this._d['set' + key](input); return this; } else { @@ -472,4 +472,4 @@ window.moment = moment; } -})(Date); \ No newline at end of file +})(Date); diff --git a/test/date.js b/test/date.js index 1a73af1ed..a45b93587 100755 --- a/test/date.js +++ b/test/date.js @@ -12,7 +12,7 @@ if (typeof window === 'undefined') { /************************************************** Tests *************************************************/ - + module("create"); @@ -227,6 +227,14 @@ test("setters", 7, function() { equal(a.seconds(), 8, 'second'); }); +test("setters - falsey values", 1, function() { + var a = moment(); + // ensure minutes wasn't coincidentally 0 already + a.minutes(1); + a.minutes(0); + equal(a.minutes(), 0, 'falsey value'); +}); + test("chaining setters", 7, function() { var a = moment(); a.year(2011)