mtdowling/cron-expression

Expression with increment of ranges not always working as expected

RemkoNolten opened this issue · 0 comments

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.