March Docs

Conduit.CronParser

Conduit.CronParser — cron expression parser and next-run calculator.

Parses the standard five-field cron syntax:

┌─────── minute        (0–59)
│ ┌───── hour          (0–23)
│ │ ┌─── day-of-month  (1–31)
│ │ │ ┌─ month         (1–12)
│ │ │ │ ┌ day-of-week  (0–6, 0 = Sunday)
* * * * *

Each field may be:

  • — any value
N        — exact value
N-M      — inclusive range
N-M/S    — range with step S
*/S      — every S values from the field's minimum
a,b,c    — comma-separated list of literals or ranges

next_run finds the next DateTime after from that satisfies the expression by stepping minute-by-minute up to one year ahead.

Types

ptypeFieldField = Any | Values(List(Int))#
ptypeCronExprCronExpr = {#

Functions

fnmatchesmatches(expr : CronExpr, dt : DateTime) : Bool#

Return true if dt satisfies all five fields of the parsed expr.

Uses UTC time components (minute, hour, day-of-month, month, day-of-week).
fnnext_runnext_run(schedule : String, from : DateTime) : Result(DateTime, String)#

Parse a cron expression and return the next run time after from.

The result is the first DateTime at or after `from + 1 minute` that matches
all five fields of the expression.  The search is bounded to ~1 year
(527 040 minutes); if no match is found within that window, returns
Err with a descriptive message.

Returns:
  Ok(next_run_at)  — the next scheduled DateTime (always in the future).
  Err(msg)         — invalid expression or no match found within 1 year.
fnparseparse(schedule : String) : Result(CronExpr, String)#

Parse a cron expression into its internal CronExpr representation.