|
|
|
I was wrong with my last comment (was confused by the fact that the calendar should 'include' all time spaces which are 'excluded' by the cron expression)
So a good fix would be to change it to while (!isTimeIncluded(nextIncludedTime)) { ... if ( cronExpression.isSatisfiedBy(new Date(nextIncludedTime))) { <=== NOT added nextIncludedTime = cronExpression.getNextInvalidTimeAfter( new Date(nextIncludedTime)).getTime(); <== Note the 'invalid' } ... } Unfortunately there is no such method in CronExpression. I made a hack in my own subclass of cron calendar which looks like this: if ( getCronExpression().isSatisfiedBy( new Date( nextIncludedTime ) ) ) { do { nextIncludedTime += 1000; } while( getCronExpression().isSatisfiedBy( new Date( nextIncludedTime ) ) ); } This returns correct results (at least for my test case), but is probably very inefficient if the next included time is far in the future. Problem is corrected, but with a poorly performing solution. See related JIRA entry for more details.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
It should read IMO:
while (!isTimeIncluded(nextIncludedTime)) {
...
if ( !cronExpression.isSatisfiedBy(new Date(nextIncludedTime))) { <=== NOT added
nextIncludedTime =
cronExpression.getNextValidTimeAfter(
new Date(nextIncludedTime)).getTime();
}
...
}
However I couldn't test it yet, i.e. have no time to figure out how to build Quartz myself.