mom.date(mom.date() + days * isAdding);
}
if (months) {
- currentDate = mom.date();
- mom.date(1)
- .month(mom.month() + months * isAdding)
- .date(Math.min(currentDate, mom.daysInMonth()));
+ mom.month(mom.month() + months * isAdding);
}
if (milliseconds && !ignoreUpdateOffset) {
moment.updateOffset(mom);
},
month : function (input) {
- var utc = this._isUTC ? 'UTC' : '';
+ var utc = this._isUTC ? 'UTC' : '',
+ dayOfMonth,
+ daysInMonth;
+
if (input != null) {
if (typeof input === 'string') {
input = this.lang().monthsParse(input);
return this;
}
}
+
+ dayOfMonth = this.date();
+ this.date(1);
this._d['set' + utc + 'Month'](input);
+ this.date(Math.min(dayOfMonth, this.daysInMonth()));
+
moment.updateOffset(this);
return this;
} else {
},
"setters" : function(test) {
- test.expect(8);
+ test.expect(9);
var a = moment();
a.year(2011);
test.equal(a.minutes(), 7, 'minute');
test.equal(a.seconds(), 8, 'second');
test.equal(a.milliseconds(), 9, 'milliseconds');
+
+ // Test month() behavior. See https://github.com/timrwood/moment/pull/822
+ a = moment('20130531', 'YYYYMMDD');
+ a.month(3);
+ test.equal(a.month(), 3, 'month edge case');
+
test.done();
},