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.
    • nextExecution

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

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

      default OptionalLong nextExecution(long millis)
      Provide nearest date for next execution.
      Parameters:
      millis - - milliseconds in long.
      Returns:
      OptionalLong instance, never null. Contains next execution time or empty.
    • nextExecution

      default OptionalLong nextExecution(long millis, ZoneId zoneId)
      Provide nearest date for next execution.
      Parameters:
      millis - - milliseconds in long.
      zoneId - - ZoneId instance. If null, a NullPointerException will be raised.
      Returns:
      OptionalLong 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.
    • timeToNextExecution

      default Optional<Duration> timeToNextExecution(Instant instant)
      Provide nearest time for next execution.
      Parameters:
      instant - - Instant instance. If null, a NullPointerException will be raised.
      Returns:
      Duration instance, never null. Time to next execution.
    • timeToNextExecution

      default Optional<Duration> timeToNextExecution(Instant instant, ZoneId zoneId)
      Provide nearest time for next execution.
      Parameters:
      instant - - Instant instance. If null, a NullPointerException will be raised.
      zoneId - - ZoneId instance. If null, a NullPointerException will be raised.
      Returns:
      Duration instance, never null. Time to next execution.
    • timeToNextExecution

      default Optional<Duration> timeToNextExecution(long millis)
      Provide nearest time for next execution.
      Parameters:
      millis - - milliseconds in long.
      Returns:
      Duration instance, never null. Time to next execution.
    • timeToNextExecution

      default Optional<Duration> timeToNextExecution(long millis, ZoneId zoneId)
      Provide nearest time for next execution.
      Parameters:
      millis - - milliseconds in long.
      zoneId - - ZoneId 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.
    • lastExecution

      default Optional<Instant> lastExecution(Instant instant)
      Provide nearest date for last execution.
      Parameters:
      instant - - Instant instance. If null, a NullPointerException will be raised.
      Returns:
      Optional Instant instance, never null. Last execution time or empty.
    • lastExecution

      default Optional<Instant> lastExecution(Instant instant, ZoneId zoneId)
      Provide nearest date for last execution.
      Parameters:
      instant - - Instant instance. If null, a NullPointerException will be raised.
      zoneId - - ZoneId instance. If null, a NullPointerException will be raised.
      Returns:
      Optional Instant instance, never null. Last execution time or empty.
    • lastExecution

      default OptionalLong lastExecution(long millis)
      Provide nearest date for last execution.
      Parameters:
      millis - - milliseconds in long.
      Returns:
      OptionalLong instance, never null. Last execution time or empty.
    • lastExecution

      default OptionalLong lastExecution(long millis, ZoneId zoneId)
      Provide nearest date for last execution.
      Parameters:
      millis - - milliseconds in long.
      zoneId - - ZoneId instance. If null, a NullPointerException will be raised.
      Returns:
      OptionalLong 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.
    • timeFromLastExecution

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

      default Optional<Duration> timeFromLastExecution(Instant instant, ZoneId zoneId)
      Provide nearest time from last execution.
      Parameters:
      instant - - Instant instance. If null, a NullPointerException will be raised.
      zoneId - - ZoneId instance. If null, a NullPointerException will be raised.
      Returns:
      Duration instance, never null. Time from last execution.
    • timeFromLastExecution

      default Optional<Duration> timeFromLastExecution(long millis)
      Provide nearest time from last execution.
      Parameters:
      millis - - milliseconds in long.
      Returns:
      Duration instance, never null. Time from last execution.
    • timeFromLastExecution

      default Optional<Duration> timeFromLastExecution(long millis, ZoneId zoneId)
      Provide nearest time from last execution.
      Parameters:
      millis - - milliseconds in long.
      zoneId - - ZoneId 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.
    • isMatch

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

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

      default boolean isMatch(long millis)
      Provide feedback if a given date matches the cron expression.
      Parameters:
      millis - - milliseconds in long.
      Returns:
      true if date matches cron expression requirements, false otherwise.
    • isMatch

      default boolean isMatch(long millis, ZoneId zoneId)
      Provide feedback if a given date matches the cron expression.
      Parameters:
      millis - - milliseconds in long.
      zoneId - - ZoneId 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
    • countExecutions

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

      default int countExecutions(Instant startInstant, Instant endInstant, ZoneId zoneId)
      Provide count of times cron expression would execute between given start and end dates
      Parameters:
      startInstant - - Start date. If null, a NullPointerException will be raised.
      endInstant - - End date. If null, a NullPointerException will be raised.
      zoneId - - ZoneId instance. If null, a NullPointerException will be raised.
      Returns:
      count of executions
    • countExecutions

      default int countExecutions(long startMillis, long endMillis)
      Provide count of times cron expression would execute between given start and end dates
      Parameters:
      startMillis - - Start date in milliseconds.
      endMillis - - End date in milliseconds.
      Returns:
      count of executions
    • countExecutions

      default int countExecutions(long startMillis, long endMillis, ZoneId zoneId)
      Provide count of times cron expression would execute between given start and end dates
      Parameters:
      startMillis - - Start date in milliseconds.
      endMillis - - End date in milliseconds.
      zoneId - - ZoneId instance. 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
    • getExecutionDates

      default List<Instant> getExecutionDates(Instant startInstant, Instant endInstant)
      Provide date times when cron expression would execute between given start and end dates.
      Parameters:
      startInstant - - Start date. If null, a NullPointerException will be raised.
      endInstant - - End date. If null, a NullPointerException will be raised.
      Returns:
      list of Instants
    • getExecutionDates

      default List<Instant> getExecutionDates(Instant startInstant, Instant endInstant, ZoneId zoneId)
      Provide date times when cron expression would execute between given start and end dates.
      Parameters:
      startInstant - - Start date. If null, a NullPointerException will be raised.
      endInstant - - End date. If null, a NullPointerException will be raised.
      zoneId - - ZoneId instance. If null, a NullPointerException will be raised.
      Returns:
      list of Instants
    • getExecutionDates

      default List<Long> getExecutionDates(long startMillis, long endMillis)
      Provide date times when cron expression would execute between given start and end dates.
      Parameters:
      startMillis - - Start date in milliseconds.
      endMillis - - End date in milliseconds.
      Returns:
      list of millisecond timestamps in Long
    • getExecutionDates

      default List<Long> getExecutionDates(long startMillis, long endMillis, ZoneId zoneId)
      Provide date times when cron expression would execute between given start and end dates.
      Parameters:
      startMillis - - Start date in milliseconds.
      endMillis - - End date in milliseconds.
      zoneId - - ZoneId instance. If null, a NullPointerException will be raised.
      Returns:
      list of millisecond timestamps in Long