Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions later.js
Original file line number Diff line number Diff line change
Expand Up @@ -926,15 +926,25 @@ later = function() {
return clone;
}
function add(sched, name, min, max, inc) {
var i = min;
if (!sched[name]) {
sched[name] = [];
}
while (i <= max) {
if (sched[name].indexOf(i) < 0) {
sched[name].push(i);
var loopTo = function(start, max){
var i = start;
while ( i <= max ){
if (sched[name].indexOf(i) < 0) {
sched[name].push(i);
}
i += inc || 1;
}
i += inc || 1;
}
if ( min > max ){
var field = FIELDS[name];
loopTo(min, field[2]);
loopTo(field[1], max);
}
else{
loopTo(min, max);
}
}
function addHash(schedules, curSched, value, hash) {
Expand Down
28 changes: 22 additions & 6 deletions src/parse/cron.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,33 @@ later.parse.cron = function (expr, hasSeconds) {
* @param {Int} inc: The increment to use between min and max
*/
function add(sched, name, min, max, inc) {
var i = min;

if (!sched[name]) {
sched[name] = [];
}

while (i <= max) {
if (sched[name].indexOf(i) < 0) {
sched[name].push(i);
var loopTo = function(start, max){
var i = start;

while ( i <= max ){
if (sched[name].indexOf(i) < 0) {
sched[name].push(i);
}
i += inc || 1;
}
i += inc || 1;
}

// if the min is greater than the max, loop it
if ( min > max ){
var field = FIELDS[name];

// add up to the max value
loopTo(min, field[2]);

// loop it over
loopTo(field[1], max);
}
else{
loopTo(min, max);
}
}

Expand Down
5 changes: 5 additions & 0 deletions test/parse/cron-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ describe('Parse Cron', function() {
p.schedules[0].should.eql({M: [1,3,5]});
});

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

});

describe('day of week', function() {
Expand Down