crontab v0.8.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 of an eventually extended cron expression. (Extended = including seconds)

Find the next execution date relative to a given date for a string of an eventually extended cron expression. (Extended = including seconds)

Find the next n execution dates relative to now for a string of an eventually extended cron expression. (Extended = including seconds)

Find the next n execution dates relative to a given date for a string of an eventually extended cron expression. (Extended = including seconds)

Find the previous execution date relative to now for a string of an eventually extended cron expression. (Extended = including seconds)

Find the previous execution date relative to a given date for a string of an eventually extended cron expression

Find the previous n execution dates relative to now for a string of an eventually extended cron expression. (Extended = including seconds)

Find the previous n execution dates relative to a given date for a string of an eventually extended cron expression. (Extended = including seconds)

Check if now matches a given string of an eventually extended cron expression

Check if given date matches a given string of an eventually extended cron expression

Functions

get_next_run_date(cron_expression, extended \\ false)
get_next_run_date(binary, boolean) :: Crontab.CronScheduler.result

Find the next execution date relative to now for a string of an eventually extended cron expression. (Extended = including seconds)

Examples

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

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

iex> Crontab.get_next_run_date("* * * * *", false)
{:ok, ~N[2016-12-23 16:00:00.348751]}
get_next_run_date_relative_to(cron_expression, date, extended \\ false)
get_next_run_date_relative_to(binary, NaiveDateTime.t, boolean) :: Crontab.CronScheduler.result

Find the next execution date relative to a given date for a string of an eventually extended cron expression. (Extended = including seconds)

Examples

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

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

iex> Crontab.get_next_run_date_relative_to("* * * * *", ~N[2016-12-17 00:00:01], true)
{:ok, ~N[2016-12-17 00:00:01]}
get_next_run_dates(n, cron_expression, extended \\ false)
get_next_run_dates(pos_integer, binary, boolean) :: [Crontab.CronScheduler.result]

Find the next n execution dates relative to now for a string of an eventually extended cron expression. (Extended = including seconds)

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]}]

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

iex> Crontab.get_next_run_dates(3, "* * * * *", false)
[{: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_relative_to(n, cron_expression, date, extended \\ false)
get_next_run_dates_relative_to(pos_integer, binary, NaiveDateTime.t, boolean) :: [Crontab.CronScheduler.result]

Find the next n execution dates relative to a given date for a string of an eventually extended cron expression. (Extended = including seconds)

Examples

iex> Crontab.get_next_run_dates_relative_to(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]}]

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

iex> Crontab.get_next_run_dates_relative_to(3, "* * * * *", ~N[2016-12-17 00:00:00], false)
[{: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, extended \\ false)
get_previous_run_date(binary, boolean) :: Crontab.CronScheduler.result

Find the previous execution date relative to now for a string of an eventually extended cron expression. (Extended = including seconds)

Examples

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

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

iex> Crontab.get_previous_run_date("* * * * *", false)
{:ok, ~N[2016-12-23 16:00:00.348751]}
get_previous_run_date_relative_to(cron_expression, date, extended \\ false)
get_previous_run_date_relative_to(binary, NaiveDateTime.t, boolean) :: Crontab.CronScheduler.result

Find the previous execution date relative to a given date for a string of an eventually extended cron expression.

Examples

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

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

iex> Crontab.get_previous_run_date_relative_to("* * * * *", ~N[2016-12-17 00:00:00], false)
{:ok, ~N[2016-12-17 00:00:00]}
get_previous_run_dates(n, cron_expression, extended \\ false)
get_previous_run_dates(pos_integer, binary, boolean) :: [Crontab.CronScheduler.result]

Find the previous n execution dates relative to now for a string of an eventually extended cron expression. (Extended = including seconds)

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]}]

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

iex> Crontab.get_previous_run_dates(3, "* * * * *", false)
[{: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_relative_to(n, cron_expression, date, extended \\ false)
get_previous_run_dates_relative_to(pos_integer, binary, NaiveDateTime.t, boolean) :: [Crontab.CronScheduler.result]

Find the previous n execution dates relative to a given date for a string of an eventually extended cron expression. (Extended = including seconds)

Examples

iex> Crontab.get_previous_run_dates_relative_to(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]}]

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

iex> Crontab.get_previous_run_dates_relative_to(3, "* * * * *", ~N[2016-12-17 00:00:00], false)
[{: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, extended \\ false)
matches_date(binary, boolean) ::
  {:ok, boolean} |
  Crontab.CronFormatParser.result

Check if now matches a given string of an eventually extended cron expression.

Examples

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

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

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

iex> Crontab.matches_date("*/7 * * * *", false)
{:ok, false}
matches_date_relative_to(cron_expression, date, extended \\ false)
matches_date_relative_to(binary, NaiveDateTime.t, boolean) ::
  {:ok, boolean} |
  Crontab.CronFormatParser.result

Check if given date matches a given string of an eventually extended cron expression.

Examples

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

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

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

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