Crono (crono v0.1.0)
Crono is a library to work with cron expressions.
It parses cron expressions, allows calculating future runs of the schedule, and representing an expression as a human-readable description.
Basic usage
iex> Crono.parse("5 * * * *")
{:ok, %Crono.Expression{minute: 5, hour: :*, day: :*, month: :*, weekday: :*}}
iex> ~e[5 * * * *]
%Crono.Expression{minute: 5, hour: :*, day: :*, month: :*, weekday: :*}
iex> Crono.Schedule.get_next_date(~e[5 * * * *], ~N[2023-09-01T10:00:00])
~N[2023-09-01T10:05:00]
Installation
To start off, add crono
to the list of your dependencies:
def deps do
{:crono, "~> 0.1"},
end
If you want to use the ~e[]
sigil for your expressions, also add import Crono.Expression
to
your module.
Summary
Functions
Parses a cron expression, returning a Crono.CronExpression
struct if successful.
Like Crono.parse/1
, but raises on error.
Functions
Link to this function
parse(input)
Parses a cron expression, returning a Crono.CronExpression
struct if successful.
Examples
iex> Crono.parse("* * * * *")
{:ok, %Crono.Expression{minute: :*, hour: :*, day: :*, month: :*, weekday: :*}}
iex> Crono.parse("5 * * * *")
{:ok, %Crono.Expression{minute: 5, hour: :*, day: :*, month: :*, weekday: :*}}
iex> Crono.parse("5/10 * * * *")
{:ok,%Crono.Expression{minute: [step: {5, 10}], hour: :*, day: :*, month: :*, weekday: :*}}
iex> Crono.parse("15-45 * * * *")
{:ok, %Crono.Expression{minute: [range: {15, 45}], hour: :*, day: :*, month: :*, weekday: :*}}
iex> Crono.parse("15,45 * * * *")
{:ok, %Crono.Expression{minute: [list: [15, 45]], hour: :*, day: :*, month: :*, weekday: :*}}
iex> Crono.parse("15,45 */6 14,28 * *")
{:ok, %Crono.Expression{minute: [list: [15, 45]], hour: [step: {:*, 6}], day: [list: [14, 28]], month: :*, weekday: :*}}
iex> Crono.parse("0 0 1 JAN *")
{:ok, %Crono.Expression{minute: 0, hour: 0, day: 1, month: 1, weekday: :*}}
iex> Crono.parse("0 0 * * WED")
{:ok, %Crono.Expression{minute: 0, hour: 0, day: :*, month: :*, weekday: 3}}
Link to this function
parse!(input)
Like Crono.parse/1
, but raises on error.