Skip to content

Commit 734f8aa

Browse files
committed
Wrapping months
1 parent db10d0f commit 734f8aa

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

src/parse/cron.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,33 @@ later.parse.cron = function (expr, hasSeconds) {
7979
* @param {Int} inc: The increment to use between min and max
8080
*/
8181
function add(sched, name, min, max, inc) {
82-
var i = min;
83-
84-
if (!sched[name]) {
82+
if (!sched[name]) {
8583
sched[name] = [];
8684
}
8785

88-
while (i <= max) {
89-
if (sched[name].indexOf(i) < 0) {
90-
sched[name].push(i);
86+
var loopTo = function(start, max){
87+
var i = start;
88+
89+
while (i <= max) {
90+
if (sched[name].indexOf(i) < 0) {
91+
sched[name].push(i);
92+
}
93+
i += inc || 1;
9194
}
92-
i += inc || 1;
95+
}
96+
97+
// if the min is greater than the max, loop it
98+
if (min > max) {
99+
var field = FIELDS[name];
100+
101+
// add up to the max value
102+
loopTo(min, field[2]);
103+
104+
// loop it over
105+
loopTo(field[1], max);
106+
}
107+
else{
108+
loopTo(min, max);
93109
}
94110
}
95111

test/parse/cron-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ describe('Parse Cron', function() {
262262
p.schedules[0].should.eql({M: [1,3,5]});
263263
});
264264

265+
it('should parse a wrapped range value', function() {
266+
var p = parse('* * * * 11-2 *', true);
267+
p.schedules[0].should.eql({M: [11,12,1,2]});
268+
});
265269
});
266270

267271
describe('day of week', function() {

0 commit comments

Comments
 (0)