View Source Antikythera.Cron (antikythera v0.5.1)

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 "/<skip>" 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.

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.

Types

Functions

@spec day_of_month(t()) :: Antikythera.Cron.DayOfMonth.t()

Type-aware getter for day_of_month.

@spec day_of_month(t(), Antikythera.Cron.DayOfMonth.t()) :: t()

Type-aware setter for day_of_month.

@spec day_of_week(t()) :: Antikythera.Cron.DayOfWeek.t()

Type-aware getter for day_of_week.

@spec day_of_week(t(), Antikythera.Cron.DayOfWeek.t()) :: t()

Type-aware setter for day_of_week.

@spec hour(t()) :: Antikythera.Cron.Hour.t()

Type-aware getter for hour.

@spec hour(t(), Antikythera.Cron.Hour.t()) :: t()

Type-aware setter for hour.

@spec minute(t()) :: Antikythera.Cron.Minute.t()

Type-aware getter for minute.

@spec minute(t(), Antikythera.Cron.Minute.t()) :: t()

Type-aware setter for minute.

@spec month(t()) :: Antikythera.Cron.Month.t()

Type-aware getter for month.

@spec month(t(), Antikythera.Cron.Month.t()) :: t()

Type-aware setter for month.

@spec new(term()) :: Croma.Result.t(t())

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
@spec new!(term()) :: t()

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

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

@spec next(t(), Antikythera.Time.t()) :: Antikythera.Time.t()
Link to this function

next_in_epoch_milliseconds(cron, t)

View Source
@spec parse(String.t()) :: Croma.Result.t(t())
@spec parse!(String.t()) :: t()
@spec source(t()) :: Croma.String.t()

Type-aware getter for source.

@spec source(t(), Croma.String.t()) :: t()

Type-aware setter for source.

@spec update(t(), Dict.t()) :: Croma.Result.t(t())

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

@spec 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.

@spec valid?(term()) :: boolean()

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