crontab v0.6.0 Crontab

This Library is built to parse & write cron expressions, test them against a given date and finde the next execution date.

In the main module defined are helper functions which work directlyfrom a string cron expression.

Summary

Functions

Find the next execution date relative to now for a string cron expression

Find the next execution date relative to a given date for a string cron expression

Find the next n execution dates relative to now for a string cron expression

Find the next n execution dates relative to a given date for a string cron expression

Find the previous execution date relative to now for a string cron expression

Find the previous execution date relative to a given date for a string cron expression

Find the previous n execution dates relative to now for a string cron expression

Find the previous n execution dates relative to a given date for a string cron expression

Check if now matches a given string cron expression

Check if given date matches a given string cron expression

Functions

get_next_run_date(cron_expression)

Find the next execution date relative to now for a string cron expression.

Examples

iex> Crontab.get_next_run_date("* * * * *")
{:ok, ~N[2016-12-23 16:00:00.348751]}
get_next_run_date(cron_expression, date)

Find the next execution date relative to a given date for a string cron expression.

Examples

iex> Crontab.get_next_run_date("* * * * *", ~N[2016-12-17 00:00:00])
{:ok, ~N[2016-12-17 00:00:00]}
get_next_run_dates(n, cron_expression)

Find the next n execution dates relative to now for a string cron expression.

Examples

iex> Crontab.get_next_run_dates(3, "* * * * *")
[{:ok, ~N[2016-12-23 16:00:00]},
 {:ok, ~N[2016-12-23 16:01:00]},
 {:ok, ~N[2016-12-23 16:02:00]}]
get_next_run_dates(n, cron_expression, date)

Find the next n execution dates relative to a given date for a string cron expression.

Examples

iex> Crontab.get_next_run_dates(3, "* * * * *", ~N[2016-12-17 00:00:00])
[{:ok, ~N[2016-12-17 00:00:00]},
 {:ok, ~N[2016-12-17 00:01:00]},
 {:ok, ~N[2016-12-17 00:02:00]}]
get_previous_run_date(cron_expression)

Find the previous execution date relative to now for a string cron expression.

Examples

iex> Crontab.get_previous_run_date("* * * * *")
{:ok, ~N[2016-12-23 16:00:00.348751]}
get_previous_run_date(cron_expression, date)

Find the previous execution date relative to a given date for a string cron expression.

Examples

iex> Crontab.get_previous_run_date("* * * * *", ~N[2016-12-17 00:00:00])
{:ok, ~N[2016-12-17 00:00:00]}
get_previous_run_dates(n, cron_expression)

Find the previous n execution dates relative to now for a string cron expression.

Examples

iex> Crontab.get_previous_run_dates(3, "* * * * *")
[{:ok, ~N[2016-12-23 16:00:00]},
 {:ok, ~N[2016-12-23 15:59:00]},
 {:ok, ~N[2016-12-23 15:58:00]}]
get_previous_run_dates(n, cron_expression, date)

Find the previous n execution dates relative to a given date for a string cron expression.

Examples

iex> Crontab.get_previous_run_dates(3, "* * * * *", ~N[2016-12-17 00:00:00])
[{:ok, ~N[2016-12-17 00:00:00]},
 {:ok, ~N[2016-12-16 23:59:00]},
 {:ok, ~N[2016-12-16 23:58:00]}]
matches_date(cron_expression)

Check if now matches a given string cron expression.

Examples

iex> Crontab.matches_date("*/2 * * * *")
{:ok, true}

iex> Crontab.matches_date("*/7 * * * *")
{:ok, false}
matches_date(cron_expression, date)

Check if given date matches a given string cron expression.

Examples

iex> Crontab.matches_date("*/2 * * * *", ~N[2016-12-17 00:02:00])
{:ok, true}

iex> Crontab.matches_date("*/7 * * * *", ~N[2016-12-17 00:06:00])
{:ok, false}