Java Code Examples for com.cronutils.model.time.ExecutionTime#isMatch()
The following examples show how to use
com.cronutils.model.time.ExecutionTime#isMatch() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimeUtil.java From styx with Apache License 2.0 | 5 votes |
/** * Gets the last execution instant for a {@link Schedule}, relative to a given instant. If * the given instant is exactly at an execution time of the schedule, it will be returned * as is. * * <p>e.g. an hourly schedule has a last execution instant at 13:00 relative to 13:22. * * @param instant The instant to calculate the last execution instant relative to * @param schedule The schedule of executions * @return an instant at the last execution time */ public static Instant lastInstant(Instant instant, Schedule schedule) { final ExecutionTime executionTime = ExecutionTime.forCron(cron(schedule)); final ZonedDateTime utcDateTime = instant.atZone(UTC); // executionTime.isMatch ignores seconds for unix cron // so we fail the check immediately if there is a sub-minute value return (instant.truncatedTo(ChronoUnit.MINUTES).equals(instant) && executionTime.isMatch(utcDateTime)) ? instant : executionTime.lastExecution(utcDateTime) .orElseThrow(IllegalArgumentException::new) // with unix cron, this should not happen .toInstant(); }
Example 2
Source File: TimeUtil.java From styx with Apache License 2.0 | 5 votes |
/** * Tests if a given instant is aligned with the execution times of a {@link Schedule}. * * @param instant The instant to test * @param schedule The schedule to test against * @return true if the given instant aligns with the schedule */ public static boolean isAligned(Instant instant, Schedule schedule) { // executionTime.isMatch ignores seconds for unix cron // so we fail the check immediately if there is a sub-minute value if (!instant.truncatedTo(ChronoUnit.MINUTES).equals(instant)) { return false; } final ExecutionTime executionTime = ExecutionTime.forCron(cron(schedule)); final ZonedDateTime utcDateTime = instant.atZone(UTC); return executionTime.isMatch(utcDateTime); }
Example 3
Source File: Issue332Test.java From cron-utils with Apache License 2.0 | 5 votes |
@Test public void testIsMatchDailightSavingsChange_loop() { CronParser cronparser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX)); ZonedDateTime date = ZonedDateTime.of(2018, 8, 12, 3, 0, 0, 0, ZoneId.of("America/Santiago")); Cron cron = cronparser.parse("0 6 * * *"); ExecutionTime exectime = ExecutionTime.forCron(cron); exectime.isMatch(date); }
Example 4
Source File: Issue218Test.java From cron-utils with Apache License 2.0 | 5 votes |
@Test public void testCronDefinitionExecutionTimeGenerator() { final CronDefinition cronDefinition = defineCron().withMinutes().and() .withHours().and() .withDayOfWeek() .optional() .and() .instance(); final CronParser parser = new CronParser(cronDefinition); final Cron cron = parser.parse(CRON_EXPRESSION); final ExecutionTime executionTime = ExecutionTime.forCron(cron); executionTime.isMatch(ZonedDateTime.now()); }