Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

setters - falsey values #31

Closed
wants to merge 1 commit into from

2 participants

@braddunbar

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.

@timrwood
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.

@braddunbar

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

@braddunbar braddunbar closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 24, 2011
  1. @braddunbar

    setters - falsey values

    braddunbar authored
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 3 deletions.
  1. +2 −2 moment.js
  2. +9 −1 test/date.js
View
4 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);
+})(Date);
View
10 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)
Something went wrong with that request. Please try again.