Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lastExecution not correct #403

Open
aibany opened this issue Oct 30, 2019 · 7 comments
Open

lastExecution not correct #403

aibany opened this issue Oct 30, 2019 · 7 comments

Comments

@aibany
Copy link

aibany commented Oct 30, 2019

图片

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
Copy link
Author

aibany commented Oct 30, 2019

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

@jmrozanec
Copy link
Owner

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

@aibany
Copy link
Author

aibany commented Oct 30, 2019

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

@jmrozanec
Copy link
Owner

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

@aibany
Copy link
Author

aibany commented Nov 5, 2019

@brusazorzo thank you.

@jmrozanec jmrozanec reopened this May 1, 2020
IndeedSi added a commit to IndeedSi/cron-utils that referenced this issue Oct 12, 2020
@IndeedSi
Copy link

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.

@jmrozanec
Copy link
Owner

jmrozanec commented Oct 12, 2020

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

jmrozanec added a commit that referenced this issue Oct 12, 2020
jmrozanec added a commit that referenced this issue Oct 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants