CronstrueEx (CronstrueEx v0.1.0)

Copy Markdown View Source

Converts standard cron expressions into human-readable descriptions.

CronstrueEx currently supports five-field cron expressions in English and Spanish. It describes a schedule but does not calculate its next execution time.

Summary

Functions

Converts a five-field cron expression to a human-readable description.

Functions

to_string(expression, options \\ [])

@spec to_string(
  String.t(),
  keyword()
) :: String.t()

Converts a five-field cron expression to a human-readable description.

The supported options are:

  • :locale - accepts English ("en"/:en) or Spanish ("es"/:es)
  • :verbose - includes wording normally omitted for brevity
  • :use_24_hour_time_format - overrides the locale's default clock format
  • :trim_hours_leading_zero - removes the leading zero from hours
  • :throw_exception_on_parse_error - returns a localized generic error description instead of raising when set to false

Examples

iex> CronstrueEx.to_string("* * * * *")
"Every minute"

iex> CronstrueEx.to_string("*/5 * * * *")
"Every 5 minutes"

iex> CronstrueEx.to_string("30 11 * * 1-5")
"At 11:30 AM, Monday through Friday"

iex> CronstrueEx.to_string("30 22 * * *", use_24_hour_time_format: true)
"At 22:30"

iex> CronstrueEx.to_string("*/5 * * * *", locale: "es")
"Cada 5 minutos"