Kathikon.Cron.Expression (Kathikon v0.2.1)

Copy Markdown View Source

Minimal 5-field cron expression parser and matcher.

Supports fixed values and * wildcards for minute, hour, day-of-month, month, and day-of-week (0–6, Sunday = 0). Fields are matched in the timezone configured via config :kathikon, timezone: ....

Presets

Shorthand macros expand to standard cron expressions:

  • @hourly0 * * * *
  • @daily0 0 * * *
  • @midnight0 0 * * *
  • @weekly0 0 * * 0
  • @monthly0 0 1 * *
  • @yearly0 0 1 1 *
  • @annually0 0 1 1 *

Presets are case-insensitive (@Daily = @daily).

Summary

Functions

Returns whether a cron expression is due at now, given the last fire time.

Expands preset macros to a canonical 5-field cron string.

Parses a cron expression.

Returns whether a cron expression is valid.

Types

parsed()

@type parsed() ::
  {minute :: term(), hour :: term(), dom :: term(), mon :: term(),
   dow :: term()}

Functions

due?(cron, last_fired, now)

@spec due?(String.t(), DateTime.t() | nil, DateTime.t()) :: boolean()

Returns whether a cron expression is due at now, given the last fire time.

expand(expression)

@spec expand(String.t()) :: String.t()

Expands preset macros to a canonical 5-field cron string.

Returns the input unchanged when it is not a known preset.

parse(expression)

@spec parse(String.t()) :: {:ok, parsed()} | {:error, :invalid_cron}

Parses a cron expression.

Returns {:ok, parsed} or {:error, :invalid_cron}.

valid?(expression)

@spec valid?(String.t()) :: boolean()

Returns whether a cron expression is valid.