diff --git a/lib/tbd.js b/lib/tbd.js index 05f3389..69f3b08 100644 --- a/lib/tbd.js +++ b/lib/tbd.js @@ -162,26 +162,27 @@ start = new Date(start.getFullYear(), start.getMonth(), start.getDate(), start.getHours(), start.getMinutes(), start.getSeconds(), start.getMilliseconds()); switch(dateType) { case 'y': - start.setFullYear(start.getFullYear() + inc++); + start.setFullYear(start.getFullYear() + inc); break; case 'M': - start.setMonth(start.getMonth() + inc++); + start.setMonth(start.getMonth() + inc); break; case 'd': - start.setDate(start.getDate() + inc++); + start.setDate(start.getDate() + inc); break; case 'h': - start.setHours(start.getHours() + inc++); + start.setHours(start.getHours() + inc); break; case 'm': - start.setMinutes(start.getMinutes() + inc++); + start.setMinutes(start.getMinutes() + inc); break; case 's': - start.setSeconds(start.getSeconds() + inc++); + start.setSeconds(start.getSeconds() + inc); break; default: throw 'The value ' + dateType + ' is not an understood date part'; } + inc = inc || 1; return start; }; } else { diff --git a/tests/until-sequential-spec.js b/tests/until-sequential-spec.js index 155335c..bc7c9d2 100644 --- a/tests/until-sequential-spec.js +++ b/tests/until-sequential-spec.js @@ -108,4 +108,15 @@ describe('tbd-util-sequantial', function() { expect(data[0].foo.getSeconds()).toEqual(start.getSeconds()); expect(data[1].foo.getSeconds()).toEqual(start.getSeconds() + 1); }); + + it('should know that going past the end of a month rolls over to a new month', function () { + var start = new Date(2011, 2, 1), + data = tbd.from({}) + .prop('foo').use(tbd.utils.sequential(start, 'd')) + .make(30); + + //just of note you have to +1 the month as it returns a 0-based month index + expect(data[29].foo.getMonth() + 1).not.toEqual(2); + expect(data[29].foo.getMonth() + 1).toEqual(3); + }); }); \ No newline at end of file