From 4eea1f561cf2a264e94a5482fb0695db103de363 Mon Sep 17 00:00:00 2001 From: Brad Dunbar Date: Mon, 24 Oct 2011 18:17:02 -0400 Subject: [PATCH] setters - falsey values --- moment.js | 4 ++-- test/date.js | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) 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) -- 2.47.2