Interface ExecutionTime

All Known Implementing Classes:
CompositeExecutionTime, SingleExecutionTime

public interface ExecutionTime
Calculates execution time given a cron pattern.
  • Method Details

    • forCron

      static ExecutionTime forCron(Cron cron)
      Creates execution time for given Cron.
      Parameters:
      cron - - Cron instance
      Returns:
      ExecutionTime instance
    • nextExecution

      Optional<ZonedDateTime> nextExecution(ZonedDateTime date)
      Provide nearest date for next execution.
      Parameters:
      date - - ZonedDateTime instance. If null, a NullPointerException will be raised.
      Returns:
      Optional ZonedDateTime instance, never null. Contains next execution time or empty.
    • timeToNextExecution

      Optional<Duration> timeToNextExecution(ZonedDateTime date)
      Provide nearest time for next execution. Due to the question #468 we clarify: crons execute on local instance time. See: https://serverfault.com/questions/791713/what-time-zone-is-a-cron-job-using We ask for a ZonedDateTime for two reasons: (i) to provide flexibility on which timezone the cron is being executed (ii) to be able to reproduce issues regardless of our own local time (e.g.: daylight savings, etc.)
      Parameters:
      date - - ZonedDateTime instance. If null, a NullPointerException will be raised.
      Returns:
      Duration instance, never null. Time to next execution.
    • lastExecution

      Optional<ZonedDateTime> lastExecution(ZonedDateTime date)
      Provide nearest date for last execution. Due to the question #468 we clarify: crons execute on local instance time. See: https://serverfault.com/questions/791713/what-time-zone-is-a-cron-job-using We ask for a ZonedDateTime for two reasons: (i) to provide flexibility on which timezone the cron is being executed (ii) to be able to reproduce issues regardless of our own local time (e.g.: daylight savings, etc.)
      Parameters:
      date - - ZonedDateTime instance. If null, a NullPointerException will be raised.
      Returns:
      Optional ZonedDateTime instance, never null. Last execution time or empty.
    • timeFromLastExecution

      Optional<Duration> timeFromLastExecution(ZonedDateTime date)
      Provide nearest time from last execution.
      Parameters:
      date - - ZonedDateTime instance. If null, a NullPointerException will be raised.
      Returns:
      Duration instance, never null. Time from last execution.
    • isMatch

      boolean isMatch(ZonedDateTime date)
      Provide feedback if a given date matches the cron expression.
      Parameters:
      date - - ZonedDateTime instance. If null, a NullPointerException will be raised.
      Returns:
      true if date matches cron expression requirements, false otherwise.
    • countExecutions

      default int countExecutions(ZonedDateTime startDate, ZonedDateTime endDate)
      Provide count of times cron expression would execute between given start and end dates
      Parameters:
      startDate - - Start date. If null, a NullPointerException will be raised.
      endDate - - End date. If null, a NullPointerException will be raised.
      Returns:
      count of executions
    • getExecutionDates

      default List<ZonedDateTime> getExecutionDates(ZonedDateTime startDate, ZonedDateTime endDate)
      Provide date times when cron expression would execute between given start and end dates. End date should be after start date. Otherwise, IllegalArgumentException is raised
      Parameters:
      startDate - - Start date. If null, a NullPointerException will be raised.
      endDate - - End date. If null, a NullPointerException will be raised.
      Returns:
      list of date times