Skip to content
This repository

setters - falsey values #31

Closed
wants to merge 1 commit into from

2 participants

brad dunbar Tim Wood
brad dunbar

When using setters with falsey values (e.g. 0) the getter is called instead. This is fixed by a null comparison to use the setter for anything but null and undefined.

Tim Wood
Owner

Ah yes, that slipped by me.

Can you change the pull request to the dev branch though? I'm working on stuff for 1.1.0 and I want this to make it in.

brad dunbar

Sure! I'll just create a new pull request I suppose? I don't see a way to change it retroactively.

brad dunbar braddunbar closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Oct 24, 2011
brad dunbar setters - falsey values 4eea1f5
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 11 additions and 3 deletions. Show diff stats Hide diff stats

  1. 4  moment.js
  2. 10  test/date.js
4  moment.js
@@ -442,7 +442,7 @@
442 442
     // helper for adding shortcuts
443 443
     function makeShortcut(name, key) {
444 444
         moment.fn[name] = function (input) {
445  
-            if (input) {
  445
+            if (input != null) {
446 446
                 this._d['set' + key](input);
447 447
                 return this;
448 448
             } else {
@@ -472,4 +472,4 @@
472 472
         window.moment = moment;
473 473
     }
474 474
 
475  
-})(Date);
  475
+})(Date);
10  test/date.js
@@ -12,7 +12,7 @@ if (typeof window === 'undefined') {
12 12
 /**************************************************
13 13
   Tests
14 14
  *************************************************/
15  
- 
  15
+
16 16
 
17 17
 module("create");
18 18
 
@@ -227,6 +227,14 @@ test("setters", 7, function() {
227 227
     equal(a.seconds(), 8, 'second');
228 228
 });
229 229
 
  230
+test("setters - falsey values", 1, function() {
  231
+    var a = moment();
  232
+    // ensure minutes wasn't coincidentally 0 already
  233
+    a.minutes(1);
  234
+    a.minutes(0);
  235
+    equal(a.minutes(), 0, 'falsey value');
  236
+});
  237
+
230 238
 test("chaining setters", 7, function() {
231 239
     var a = moment();
232 240
     a.year(2011)
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.