Class CronDescriber

java.lang.Object
com.kingsrook.qqq.backend.core.scheduler.CronDescriber

public class CronDescriber extends Object
class to give a human-friendly descriptive string from a cron expression. Note that this implementation is written specifically for quartz, without much thought to other cron variants.

description strings are like, for example:

  • Every day, at 11:00 am
  • Every day, at 12:00 am, every 5 seconds between 00 and 59
  • Every week, every day between Monday and Friday, at 12:00 am
  • Every month, every day between the 10th and 15th, at 12:00 am
  • In January, on the 1st, at 12:00 am
  • Constructor Details

    • CronDescriber

      public CronDescriber()
  • Method Details

    • getDescription

      public static String getDescription(String cronExpression) throws ParseException
      Generate a human-readable description for the given cron expression
      Parameters:
      cronExpression - cron string to describe. Must be a valid (quartz) cron string.
      Returns:
      human-readable description of the cron string
      Throws:
      ParseException - if wrong number of parts, or invalid values, etc.
    • setDescriptionInRecord

      public static void setDescriptionInRecord(QRecord record, String fieldName, String cronExpression)
      set the specified fieldName to the description for the given cronExpression in the given record - and if there's an error generating the description, then set the fieldName to an error message (don't throw). This gives a little degree of safety in case we can't describe a valid cron string (it could happen!) e.g., to prevent an error from saving a record if you were just calling record.setValue(fieldName, getDescription(...)) directly (e.g., and it threw).
      Parameters:
      record - record to set the value in
      fieldName - field name to set in the record
      cronExpression - cron string to describe