Class CronTab

java.lang.Object
hudson.scheduler.CronTab

public final class CronTab extends Object
Table for driving scheduled tasks.
Author:
Kohsuke Kawaguchi
  • Constructor Details

    • CronTab

      public CronTab(String format)
      Parameters:
      format - the crontab entry to be parsed
      Throws:
      IllegalArgumentException - if the crontab entry cannot be parsed
    • CronTab

      public CronTab(String format, Hash hash)
      Parameters:
      format - the crontab entry to be parsed
      Throws:
      IllegalArgumentException - if the crontab entry cannot be parsed
    • CronTab

      @Deprecated(since="1.448") public CronTab(String format, int line)
      Parameters:
      format - the crontab entry to be parsed
      Throws:
      IllegalArgumentException - if the crontab entry cannot be parsed
    • CronTab

      public CronTab(String format, int line, Hash hash)
      Parameters:
      format - the crontab entry to be parsed
      hash - Used to spread out token like "@daily". Null to preserve the legacy behaviour of not spreading it out at all.
      Throws:
      IllegalArgumentException - if the crontab entry cannot be parsed
    • CronTab

      public CronTab(String format, int line, Hash hash, @CheckForNull String timezone)
      Parameters:
      format - the crontab entry to be parsed
      timezone - Used to schedule cron in a different timezone. Null to use the default system timezone
      Throws:
      IllegalArgumentException - if the crontab entry cannot be parsed
      Since:
      1.615
  • Method Details

    • ceil

      public Calendar ceil(long t)
      Computes the nearest future timestamp that matches this cron tab.

      More precisely, given the time 't', computes another smallest time x such that:

      • x ≥ t (inclusive)
      • x matches this crontab

      Note that if t already matches this cron, it's returned as is.

    • ceil

      public Calendar ceil(Calendar cal)
      See ceil(long). This method modifies the given calendar and returns the same object.
      Throws:
      RareOrImpossibleDateException - if the date isn't hit in the 2 years after it indicates an impossible (e.g. Jun 31) date, or at least a date too rare to be useful. This addresses JENKINS-41864 and was added in 2.49
    • floor

      public Calendar floor(long t)
      Computes the nearest past timestamp that matched this cron tab.

      More precisely, given the time 't', computes another smallest time x such that:

      • x <= t (inclusive)
      • x matches this crontab

      Note that if t already matches this cron, it's returned as is.

    • floor

      public Calendar floor(Calendar cal)
      See floor(long) This method modifies the given calendar and returns the same object.
      Throws:
      RareOrImpossibleDateException - if the date isn't hit in the 2 years before it indicates an impossible (e.g. Jun 31) date, or at least a date too rare to be useful. This addresses JENKINS-41864 and was added in 2.49
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • checkSanity

      @CheckForNull public String checkSanity()
      Checks if this crontab entry looks reasonable, and if not, return an warning message.

      The point of this method is to catch syntactically correct but semantically suspicious combinations, like "* 0 * * *"

    • hashify

      @CheckForNull public static String hashify(String spec)
      Checks a prospective crontab specification to see if it could benefit from balanced hashes.
      Parameters:
      spec - a (legal) spec
      Returns:
      a similar spec that uses a hash, if such a transformation is necessary; null if it is OK as is
      Since:
      1.510
    • getTimeZone

      @CheckForNull public TimeZone getTimeZone()
      Returns the configured time zone, or null if none is configured
      Returns:
      the configured time zone, or null if none is configured
      Since:
      2.54