# Module cloudi_cron

- Description
- Data Types
- Function Index
- Function Details

### CloudI Cron Expression Functionality

The special character ? and the @reboot macro are not supported because they wouldn't work well with Erlang process restarts.

Copyright © 2019-2020 Michael Truog

Version: 2.0.1 Dec 3 2021 19:11:42 ------------------------------------------------------------------------

Authors: Michael Truog (`mjtruog at protonmail dot com`).

## Description

### CloudI Cron Expression Functionality

The special character ? and the @reboot macro are not supported because they wouldn't work well with Erlang process restarts. The other Cron expression syntax is implemented, including the optional seconds and year values (info from https://en.wikipedia.org/wiki/Cron#CRON_expression):

       Field name     Required     Allowed values    Allowed special characters
       ----------     --------     --------------    --------------------------
       Seconds        No           0-59              * / , -
       Minutes        Yes          0-59              * / , -
       Hours          Yes          0-23              * / , -
       Day of month   Yes          1-31              * / , - L W
       Month          Yes          1-12 or JAN-DEC   * / , -
       Day of week    Yes          0-6 or SUN-SAT    * / , - L #
       Year           No           1970–9999         * / , -

#### Asterisk (*)

An asterisk indicates that the cron expression matches for all values of the field.

#### Slash (/)

Slashes can be combined with ranges to specify step values. For example, */5 in the minutes field indicates every 5 minutes.

#### Comma (,)

Commas are used to separate items of a list. For example, using "MON,WED,FRI" in the day-of-week field means Mondays, Wednesdays and Fridays.

#### Hyphen (-)

Hyphens define ranges. For example, 2000–2010 indicates every year between 2000 and 2010, inclusive.

#### L

'L' stands for "last". When used in the day-of-week field, it allows you to specify constructs such as "the last Friday" ("5L") of a given month. In the day-of-month field, it specifies the last day of the month.

#### W

The 'W' character is allowed for the day-of-month field. This character is used to specify the weekday (Monday-Friday) nearest the given day. As an example, if you were to specify "15W" as the value for the day-of-month field, the meaning is: "the nearest weekday to the 15th of the month". So, if the 15th is a Saturday, the trigger fires on Friday the 14th. If the 15th is a Sunday, the trigger fires on Monday the 16th. If the 15th is a Tuesday, then it fires on Tuesday the 15th. However, if you specify "1W" as the value for day-of-month, and the 1st is a Saturday, the trigger fires on Monday the 3rd, as it does not 'jump' over the boundary of a month's days.

This implementation allows the W character to be used in a list. For example, "1W,15W" is valid in the day-of-month field.

The W character can be combined with L as LW to mean "the last business day of the month".

#### Hash (#)

'#' is allowed for the day-of-week field, and must be followed by a number between one and five. It allows you to specify constructs such as "the second Friday" of a given month. For example, entering "5#3" in the day-of-week field corresponds to the third Friday of every month.

#### Other Details

       * If only six fields are present,
         a 0 second field is prepended
       * If only five fields are present,
         a 0 second field is prepended and a wildcard year field is appended
       * The range for the day-of-week field is 0-7 instead of 0-6,
         with 7 as Sunday (like 0) (BSD and ATT disagreed about this in the past)
       * The month names are case-insensitive
       * The day-of-week names are case-insensitive

## Data Types

### expression()

`expression() = {field_seconds(), field_minutes(), field_hours(), field_day_of_month(), field_month(), field_day_of_week(), field_year()}`

### expression_strings()

`expression_strings() = {nonempty_string(), nonempty_string(), nonempty_string(), nonempty_string(), nonempty_string(), nonempty_string(), nonempty_string()}`

### field_day_of_month()

`field_day_of_month() = [1..31 | last_day_of_month | {weekday, last_day_of_month | 1..31}, ...] | undefined`

### field_day_of_week()

`field_day_of_week() = [0..6 | {last_day_of_week, 0..6} | {every, 1..5, 0..6}, ...] | undefined`

### field_hours()

`field_hours() = [0..23, ...] | undefined`

### field_minutes()

`field_minutes() = [0..59, ...] | undefined`

### field_month()

`field_month() = [1..12, ...] | undefined`

### field_seconds()

`field_seconds() = [0..59, ...] | undefined`

### field_year()

`field_year() = [1970..9999, ...] | undefined`

### state()

`state() = #cloudi_cron{expression_strings = expression_strings(), expression = expression()}`

## Function Index

expression/1 | #### Provide the cron expression string. .
new/1 | #### Create a parsed representation of a cron expression. .
next_datetime/2 | #### Determine the next datetime based on the cron expression. .

## Function Details

### expression/1

`expression(Cloudi_cron::state()) -> nonempty_string()`

#### Provide the cron expression string.

### new/1

`new(Input::nonempty_string()) -> state()`

#### Create a parsed representation of a cron expression.

### next_datetime/2

`next_datetime(DateTime::calendar:datetime(), Cloudi_cron::state()) -> calendar:datetime() | undefined`

#### Determine the next datetime based on the cron expression.

Generated by EDoc