bunkat / later

A javascript library for defining recurring schedules and calculating future (or past) occurrences for them. Includes support for using English phrases and Cron schedules. Works in Node and in the browser.
http://bunkat.github.io/later/
MIT License
2.42k stars 245 forks source link

cron day/weekday issue #11

Open mykhailosh opened 11 years ago

mykhailosh commented 11 years ago

if we have both day and weekday values, there is an incorrect calculation. See sample: http://jsfiddle.net/SmYqS/

man 5 crontab: Note: The day of a command's execution can be specified by two fields — day of month, and day of week. If both fields are restricted (i.e., aren't *), the command will be run when either field matches the current time.

bunkat commented 11 years ago

Thanks for catching this. I remember reading that and then apparently completely forgot about it. I'll create a fix shortly, but in the meantime you can work around this by breaking up the cron schedule and concatenating the results:

var s1 = cronParser().parse('* * 10 * *');
var s2 = cronParser().parse('* * * * 5');

s1.schedules = s1.schedules.concat(s2.schedules);
s1.exceptions = s1.exceptions.concat(s2.exceptions);

var result = later(60, true).getNext(s1);
mykhailosh commented 10 years ago

How it should work now? The next code is not work

var scheduler1 = later.parse.cron( '*  *  10  *  *' );
var scheduler2 = later.parse.cron( '*  *  *  *  5' );

scheduler1.schedules  = scheduler1.schedules.concat( scheduler2.schedules );
scheduler1.exceptions = scheduler1.exceptions.concat( scheduler2.exceptions );

var result = later.schedule(scheduler1).next();