Cron utils for parsing, validations and human readable descriptions as well as date/time interoperability.
jmrozanec on master
Update README.md (compare)
jmrozanec on master
Add support for Romanian (compare)
jmrozanec on master
Documenting thread safety. Merge branch 'master' of https:… (compare)
jmrozanec on master
Added getting execution count a… Added throwing exception when e… Clean up auto formatting and 1 more (compare)
jmrozanec on master
implement equals and hash code … Merge pull request #516 from ka… (compare)
jmrozanec on master
Create Unit tests for issue #522 Fix #522 Merge branch 'issue522' of http… and 1 more (compare)
jmrozanec on master
Remove Javassist Javassist doe… Merge branch 'javassist' of htt… Merge branch 'gastaldi-javassis… (compare)
jmrozanec on master
Fix for #517 Input Validation V… Merge branch 'echristeson-maste… Merge branch 'master' of https:… (compare)
jmrozanec on master
making the translation to Japan… Merge pull request #519 from pu… (compare)
jmrozanec on master
Fix #512 - handle previous mont… Merge pull request #513 from rd… (compare)
jmrozanec on master
Update README.md (compare)
jmrozanec on master
Update README.md (compare)
jmrozanec on master
#505: Support cron nicknames. (compare)
jmrozanec on master
#510: Add support for Japanese … (compare)
jmrozanec on master
#505: Support predefined schedu… (compare)
jmrozanec on master
Fix exception thrown when DoW s… Merge branch 'sirsha-chatterjee… (compare)
jmrozanec on master
Merge pull request #1 from jmro… added unit test to address issu… fixed #503 - DST overlap check … and 3 more (compare)
jmrozanec on master
Test for https://github.com/jmr… Merge pull request #500 from ss… (compare)
jmrozanec on master
Update README.md (compare)
jmrozanec on master
Add alternative pom.xml, with u… (compare)
@jmrozanec Thank you very much for your response! I am indeed using v7.0.4
My pom.xml includes:
<dependency>
<groupId>com.cronutils</groupId>
<artifactId>cron-utils</artifactId>
<version>7.0.4</version>
</dependency>
The code you can use to replicate the problem is as follows (sorry, I see I copied the schedule expression incorrectly in my previous message...):
String schedule = "0 0 * ? * SAT-SUN *";
CronParser parser = new CronParser(cronDefinition);
Cron quartzCron = parser.parse(schedule);
CronDescriptor descriptor = CronDescriptor.instance();
String description = descriptor.describe(quartzCron);
System.out.println(description);
ZonedDateTime time = ZonedDateTime.now();
ExecutionTime executionTime = ExecutionTime.forCron(quartzCron);
// Time from last execution to now
Duration timeFromLastExecution = executionTime.timeFromLastExecution(time).get();
System.out.println(timeFromLastExecution.toMinutes());
Hi, I'm trying to understand how to use the parser in order to compute next execution based on the last execution.
is this code should work?
ZonedDateTime lastExecution = ZonedDateTime.ofInstant(new Date(entity.getEndTime()).toInstant(), ZoneId.systemDefault());
executionTime.lastExecution(lastExecution);
ZonedDateTime now = ZonedDateTime.now();
final long millis = executionTime.timeToNextExecution(now).get().toMillis();