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

Incorrect next execution time for "month" and "day of week"

Open mjsaber opened this issue 10 years ago • 6 comments

    CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX);
    CronParser parser = new CronParser(cronDefinition);
    String crontab = "* * */3 */4 */5";
    Cron cron = parser.parse(crontab);
    ExecutionTime executionTime = ExecutionTime.forCron(cron);
    DateTime scanTime = new DateTime();
    DateTime nextExecutionTime = executionTime.nextExecution(scanTime);
    System.out.println(String.format("Scan time %s, next execution time: %s", scanTime, nextExecutionTime));

16:32:56.633 [main] DEBUG c.cronutils.model.time.ExecutionTime - computing days for [class com.cronutils.model.field.expression.Every] 16:32:56.637 [main] DEBUG c.cronutils.model.time.ExecutionTime - computing days 4 16:32:56.639 [main] DEBUG c.cronutils.model.time.ExecutionTime - computing days for [class com.cronutils.model.field.expression.Every] 16:32:56.639 [main] DEBUG c.cronutils.model.time.ExecutionTime - computing days 4 Scan time 2015-12-10T16:32:56.586-08:00, next execution time: 2015-12-10T16:33:00.000-08:00 (12/10/2015 is Thursday)

This is incorrect. Month */4 should mean Jan, May and Sep because month entry range should be (1-12), now it looks like it calculated from 0. In terms of Day of Week */5, it should be Sun, Fri, but not Thu.

mjsaber avatar Dec 11 '15 00:12 mjsaber

@mjsaber thank you for reporting this. Help is appreciated!

jmrozanec avatar Dec 11 '15 01:12 jmrozanec

I'd like to help. Any idea how should I start? Or what is the best practice to go through the code?

mjsaber avatar Dec 11 '15 01:12 mjsaber

@mjsaber I just uploaded two tests with the reported case, one for checking months behavior, another for DoW assertions. I did not made specific assertions on them. Can you check what assertions are required, and debug from there on what should be changed? Months scale is definitively an important code point to check. Let me know if I can help with further context in any piece of code. Thank you!

jmrozanec avatar Dec 11 '15 02:12 jmrozanec

@jmrozanec I think the implementation of public int generateNextValue(int reference) throws NoSuchValueException in EveryFieldValueGenerator is not correct for DoM. Take * * */3 * * as an example: generateCandidatesNotIncludingIntervalExtremes will give 3, 6, 9 ... as the result. However, it should be 1, 4, 6... I think I can help improve the implementation, how should I purpose a push request? I'm new to github..

Thanks,

mjsaber avatar Jan 26 '16 03:01 mjsaber

Hello @mjsaber! First you would need to fork this repo, then implement the changes and commit to your fork. When you are ready, you issue a pull request. I will review it, and merge into this repo. When proposing a fix, please provide some unit tests, to ensure the case is covered. Let me know if I can provide further help.

jmrozanec avatar Jan 26 '16 09:01 jmrozanec

@mjsaber Fixed and closed! Thanks for contributing a fix!

jmrozanec avatar Mar 05 '16 03:03 jmrozanec