mtdowling / cron-expression

CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due
http://mtdowling.com/blog/2012/06/03/cron-expressions-in-php/
MIT License
4.9k stars 335 forks source link

Expression with increment of ranges not always working as expected #28

Closed RemkoNolten closed 11 years ago

RemkoNolten commented 11 years ago

We have the following expression: 0-25/5,40-59/5 4 * * 0 sync content Which should fire every five minutes on sundays between 4:00 and 5:00 EXCEPT between 4:25 and 4:40 (Don't ask why :))

The problem is that this expression also fires on 4:30 since there appears to be a little error in AbstractField->isInIncrementsOfRanges. It seams that the problem appears when the range starts with a zero (like mine above).

I could fix the issue by changing:

if ($parts[0] == '*' || $parts[0] == 0) {
    return (int) $dateValue % $stepSize == 0;
}

into:

if ($parts[0] == '*' || $parts[0] === '0') {
    return (int) $dateValue % $stepSize == 0;
}

Although I don't fully understand why that second expression is there in the first place.