Open aibany opened 4 years ago
Even my cron-utils version is 8.0.0, both the problem exsisted.
@aibany thank you for reporting this. May we ask you to submit a PR with the corresponding tests? Thanks!
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 can you push this as a test into a PR? Thanks!
@brusazorzo thank you.
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 thank you! Expected executions are ok, the description is misleading.
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.