Permalink
Browse files

fixed some bugs in the date generation for large ranges

  • Loading branch information...
aaronpowell committed Dec 5, 2011
1 parent e864cde commit 337f621dbae409388d6074ca2ddd0c87f29a83ca
Showing with 18 additions and 6 deletions.
  1. +7 −6 lib/tbd.js
  2. +11 −0 tests/until-sequential-spec.js
View
@@ -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 {
@@ -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);
+ });
});

0 comments on commit 337f621

Please sign in to comment.