antikythera v0.2.0 Antikythera.Cron View Source

Calculate time schedules based on cron format strings.

parse/1 recognizes the POSIX specifications of crontab format with the extension of “step values” (explained below). The parsed object can be used to compute next matching time in next/2.

Note that all times are in UTC, as is the case with Antikythera.Time.

Schedule format

  • The cron schedule is specified by 5 fields separated by whitespaces.
  • Allowed values for each field are:

    • minutes : 0-59
    • hours : 0-23
    • day of month : 1-31
    • month : 1-12
    • day of week : 0-6 (0=Sunday)
  • Multiple elements can be used within a field by separating each by ,.
  • An element shall be either a number or two numbers separated by a - (meaning an inclusive range).
  • A field may contain * which stands for “first-last”.
  • Step values as in “/“ can be used in conjunction with ranges. For example,

    • “0-18/4” is identical to “0,4,8,12,16”, and
    • “*/10” in minutes field is identical to “0,10,20,30,40,50”.
  • If both ‘day of month’ and ‘day of week’ are not ““, then the dates are the ones matching either of the fields. For example, “30 4 1,15 5” indicates both of the followings:

    • 4:30 on the 1st and 15th of each month
    • 4:30 on every Friday
  • Schedules that actually don’t represent valid date are not allowed. For example, “0 0 31 4 *” is rejected as 31st of April does not exist.

Link to this section Summary

Functions

Type-aware getter for day_of_month

Type-aware setter for day_of_month

Type-aware getter for day_of_week

Type-aware setter for day_of_week

Type-aware getter for hour

Type-aware setter for hour

Type-aware getter for minute

Type-aware setter for minute

Type-aware getter for month

Type-aware setter for month

Creates a new instance of Antikythera.Cron by using the given dict

A variant of new/1 which returns t or raise if validation fails

Type-aware getter for source

Type-aware setter for source

Updates an existing instance of Antikythera.Cron with the given dict. The values in the dict are validated by each field’s valid?/1 function. Returns {:ok, valid_struct} or {:error, reason}

A variant of update/2 which returns t or raise if validation fails. In other words, update/2 followed by Croma.Result.get!/1

Checks if the given value belongs to t/0 or not

Link to this section Types

Link to this section Functions

Type-aware getter for day_of_month.

Link to this function day_of_month(s, field) View Source
day_of_month(t(), Antikythera.Cron.DayOfMonth.t()) :: t()

Type-aware setter for day_of_month.

Type-aware getter for day_of_week.

Link to this function day_of_week(s, field) View Source
day_of_week(t(), Antikythera.Cron.DayOfWeek.t()) :: t()

Type-aware setter for day_of_week.

Type-aware getter for hour.

Type-aware setter for hour.

Type-aware getter for minute.

Type-aware setter for minute.

Type-aware getter for month.

Type-aware setter for month.

Creates a new instance of Antikythera.Cron by using the given dict.

Returns {:ok, valid_struct} or {:error, reason}.

The values in the dict are validated by each field’s valid?/1 function. If the value was invalid, it will be passed to new/1 of the field

For missing fields, followings will be tried:

  • default/0 of each field type
  • new/1 of each field type, with empty map as input

A variant of new/1 which returns t or raise if validation fails.

In other words, new/1 followed by Croma.Result.get!/1.

Link to this function next_in_epoch_milliseconds(cron, t) View Source

Type-aware getter for source.

Link to this function source(s, field) View Source
source(t(), Croma.String.t()) :: t()

Type-aware setter for source.

Updates an existing instance of Antikythera.Cron with the given dict. The values in the dict are validated by each field’s valid?/1 function. Returns {:ok, valid_struct} or {:error, reason}.

Link to this function update!(s, dict) View Source
update!(t(), Dict.t()) :: t()

A variant of update/2 which returns t or raise if validation fails. In other words, update/2 followed by Croma.Result.get!/1.

Checks if the given value belongs to t/0 or not.