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

lastExecution not correct

Open aibany opened this issue 6 years ago • 7 comments
trafficstars

图片

Current System time is 2019-10-30 12:16:00 My cron is: 0 * 0/2 * * ? . means every 2 hours execute one times. My cron-utils version is :9.0.2

but the calc result nextTime and lastTime is both incorrect.

aibany avatar Oct 30 '19 04:10 aibany

Even my cron-utils version is 8.0.0, both the problem exsisted.

aibany avatar Oct 30 '19 04:10 aibany

@aibany thank you for reporting this. May we ask you to submit a PR with the corresponding tests? Thanks!

jmrozanec avatar Oct 30 '19 06:10 jmrozanec

public static void main(String[] args) {

        CronDefinition defaultDef = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);
        CronDescriptor descriptor = CronDescriptor.instance(Locale.CHINESE);
        CronParser parser = new CronParser(defaultDef);

        String str = "0 * 0/2 * * ?";

        String description = descriptor.describe(parser.parse(str));

        ZonedDateTime now = ZonedDateTime.now();
        ExecutionTime executionTime = ExecutionTime.forCron(parser.parse(str));
        Optional<ZonedDateTime> lastExecution = executionTime.lastExecution(now);
        Optional<ZonedDateTime> nextExecution = executionTime.nextExecution(now);
        String sb = nextExecution.get().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        System.out.println(sb);
        System.out.println("My machine time:" + new Date().toString());
    }

this console print is : 2019-10-30 18:09:00 My machine time:Wed Oct 30 18:08:50 CST 2019

aibany avatar Oct 30 '19 10:10 aibany

@aibany can you push this as a test into a PR? Thanks!

jmrozanec avatar Oct 30 '19 10:10 jmrozanec

@brusazorzo thank you.

aibany avatar Nov 05 '19 09:11 aibany

Looking at the example, I think what was causing confusion was the description. 0 * 0/2 * * ? should be every minute every 2 hours instead of simply every 2 hours

And I think the last and next execution time works just as expected since it's being triggered every minute. I added a test case for this issue.

IndeedSi avatar Oct 12 '20 08:10 IndeedSi

@IndeedSi thank you! Expected executions are ok, the description is misleading.

jmrozanec avatar Oct 12 '20 15:10 jmrozanec