Cron Parser icon

Cron Parser

Validate cron and compute next/previous occurrences (UTC or system clock)

Overview

This node validates and parses cron expressions to compute scheduled run times based on the given cron syntax. It supports different modes such as validating the expression, calculating the next scheduled runs, finding runs within a time window, or retrieving the previous run. It can evaluate the cron expression in either UTC or system local time. This node is useful for scheduling tasks, monitoring cron schedules, or integrating cron-based triggers in workflows.

Use Case Examples

  1. Validate a cron expression to ensure it is correctly formatted.
  2. Calculate the next 5 scheduled run times for a cron job starting from now or a specified date.
  3. Find all scheduled runs within a specific time window to analyze or trigger events.
  4. Retrieve the previous run time of a cron schedule for auditing or logging purposes.

Properties

Name Meaning
Expression The cron expression to validate and parse, supporting 5 to 7 fields including seconds.
Evaluate In Choose whether to evaluate the cron expression in UTC or system local time.
Mode Select the operation mode: validate only, get next runs, runs in a time window, or previous run.
Count Number of future runs to return when in 'Next Runs' mode.
Start From Anchor date/time to start calculations from; defaults to current time.
Until End date/time to include occurrences up to, used in 'Runs in Window' mode.
Skew Window (Seconds) Seconds range to consider a run as 'due now' for flagging purposes.
Include dueNow Flag Whether to include a flag indicating if a run is due now based on the skew window.

Output

JSON

  • valid - Boolean indicating if the cron expression is valid.
  • expression - The original cron expression string.
  • evalClock - The clock type used for evaluation (UTC or System Local Time).
  • error - Error message if the cron expression is invalid (only present in validation failure).
  • previous
    • utc - ISO string of the previous run time (in 'Previous Run' mode).
    • local - Local string representation of the previous run time.
    • epochMs - Epoch milliseconds of the previous run time.
    • clock - Clock type used for the previous run time.
  • startFrom
    • utc - ISO string of the anchor start time for calculations.
    • local - Local string representation of the anchor start time.
    • epochMs - Epoch milliseconds of the anchor start time.
    • clock - Clock type used for the anchor start time.
  • until
    • utc - ISO string of the end time for window mode.
    • local - Local string representation of the end time for window mode.
    • epochMs - Epoch milliseconds of the end time for window mode.
    • clock - Clock type used for the end time in window mode.
  • count - Number of runs returned.
  • runs
    • ``
      * utc - ISO string of each scheduled run time.
      * local - Local string representation of each scheduled run time.
      * epochMs - Epoch milliseconds of each scheduled run time.
      * clock - Clock type used for each scheduled run time.
  • next
    • utc - ISO string of the next run time (in 'Next Runs' mode).
    • local - Local string representation of the next run time.
    • epochMs - Epoch milliseconds of the next run time.
    • clock - Clock type used for the next run time.
  • dueNow - Boolean flag indicating if a run is due now based on skew window.
  • dueFor
    • utc - ISO string of the run time considered due now.
    • local - Local string representation of the run time considered due now.
    • epochMs - Epoch milliseconds of the run time considered due now.
    • clock - Clock type used for the run time considered due now.

Dependencies

  • cron-parser library for parsing and evaluating cron expressions
  • n8n-workflow package for node utilities and error handling

Troubleshooting

  • If the cron expression is invalid, the node returns a validation error with the error message. Ensure the cron syntax is correct and supports 5 to 7 fields including optional seconds.
  • In 'Runs in Window' mode, the 'Until' parameter is required; missing it will cause an error. Provide a valid end date/time.
  • If the node fails unexpectedly, enabling 'Continue On Fail' allows the workflow to proceed with error details in the output.
  • Time evaluation depends on the selected clock (UTC or System Local Time); ensure the correct clock is chosen to match your scheduling context.

Links

Discussion