cron-utils icon indicating copy to clipboard operation
cron-utils copied to clipboard

Unix crontab nextExecution bug

Open mjsaber opened this issue 11 years ago • 4 comments

I'm trying a simple unix crontab "* * * * 1", which should run every minute of every hour Mondays in every month, but nextExecution doesn't seem give the correct result. Following is the code:

    crontab = "* * * * 1";
    CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX);
    CronParser parser = new CronParser(cronDefinition);
    Cron cron = parser.parse(crontab);
    DateTime date = DateTime.now();
    System.out.println("now:" + date);
    ExecutionTime executionTime = ExecutionTime.forCron(cron);
    DateTime nextExecution = executionTime.nextExecution(date);
    DateTime lastExecution = executionTime.lastExecution(date);
    System.out.println("next execution:" + nextExecution);
    System.out.println("last execution:" + lastExecution);

Output: now:2015-10-13T17:26:54.468-07:00 next execution:2015-11-02T00:00:00.000-08:00 last execution:2015-10-05T23:59:00.000-07:00

The last execution time seems correct, but next execution time should be 2015-10-19T00:00:00.000-07:00. It skips two weeks and also change the time zone. Can you guys take a look at it?

Thanks, Jun

mjsaber avatar Oct 14 '15 00:10 mjsaber

@mjsaber Thank you for reporting this. We are working on a solution right now. Will keep you posted about updates on this issue.

jmrozanec avatar Oct 15 '15 01:10 jmrozanec

This issue exposes bad next/previous execution calculation as well as the fact that predicted time is always computed in local timezone, not in same timezone as reference date.

jmrozanec avatar Oct 15 '15 02:10 jmrozanec

@mjsaber the issue was fixed! Will release a new version with the fixes before weekend.

jmrozanec avatar Oct 15 '15 03:10 jmrozanec

@mjsaber Version 3.1.1 was released including this fix!

jmrozanec avatar Oct 19 '15 23:10 jmrozanec