Skip to content

Commit

Permalink
fixed some bugs in the date generation for large ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronpowell committed Dec 5, 2011
1 parent e864cde commit 337f621
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/tbd.js
Expand Up @@ -162,26 +162,27 @@
start = new Date(start.getFullYear(), start.getMonth(), start.getDate(), start.getHours(), start.getMinutes(), start.getSeconds(), start.getMilliseconds()); start = new Date(start.getFullYear(), start.getMonth(), start.getDate(), start.getHours(), start.getMinutes(), start.getSeconds(), start.getMilliseconds());
switch(dateType) { switch(dateType) {
case 'y': case 'y':
start.setFullYear(start.getFullYear() + inc++); start.setFullYear(start.getFullYear() + inc);
break; break;
case 'M': case 'M':
start.setMonth(start.getMonth() + inc++); start.setMonth(start.getMonth() + inc);
break; break;
case 'd': case 'd':
start.setDate(start.getDate() + inc++); start.setDate(start.getDate() + inc);
break; break;
case 'h': case 'h':
start.setHours(start.getHours() + inc++); start.setHours(start.getHours() + inc);
break; break;
case 'm': case 'm':
start.setMinutes(start.getMinutes() + inc++); start.setMinutes(start.getMinutes() + inc);
break; break;
case 's': case 's':
start.setSeconds(start.getSeconds() + inc++); start.setSeconds(start.getSeconds() + inc);
break; break;
default: default:
throw 'The value ' + dateType + ' is not an understood date part'; throw 'The value ' + dateType + ' is not an understood date part';
} }
inc = inc || 1;
return start; return start;
}; };
} else { } else {
Expand Down
11 changes: 11 additions & 0 deletions tests/until-sequential-spec.js
Expand Up @@ -108,4 +108,15 @@ describe('tbd-util-sequantial', function() {
expect(data[0].foo.getSeconds()).toEqual(start.getSeconds()); expect(data[0].foo.getSeconds()).toEqual(start.getSeconds());
expect(data[1].foo.getSeconds()).toEqual(start.getSeconds() + 1); 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.