skovsboll / elm-crontab / Cron

Parses a classic UNIX style crontab string into a data structure, Cron, from which you can extract information.

The main entrypoint is the fromString function.

Cron.fromString "* * */3 4 *"

fromString returns a Result (List DeadEnd) Cron.

Definition


type Cron
    = Cron (Expr Basics.Int) (Expr Basics.Int) (Expr Basics.Int) (Expr Month) (Expr WeekDay)

A Cron expression consists of exactly five elements:

1. Minutes (0-59)
2. Hours (0-23)
3. Day of month (1-31)
4. Month (1-12 or jan,feb,...)
5. Week day (0-6 or mon, tue, ...)

API

fromString : String -> Result (List Parser.DeadEnd) Cron

Parse a crontab string to a Cron expression

Syntax Tree


type Expr a
    = Single (Term a)
    | Multiple (List (Term a))
    | Every

Represents each of the five parts of a crontab

A Single is just a number or ordinal such as 1 or MON. Multiple is a comma-separated list of terms, such as 1,2,5 or JAN,FEB Every represents the star meaning "everything matches"


type Term a
    = Step (Atom a) Basics.Int
    | EveryStep Basics.Int
    | Atom (Atom a)

A term can be either:


type Atom a
    = Particle a
    | Range a a

An atom is either


type Month
    = January
    | February
    | March
    | April
    | May
    | June
    | July
    | August
    | September
    | October
    | November
    | December

The months of the year


type WeekDay
    = Sunday
    | Monday
    | Tuesday
    | Wednesday
    | Thursday
    | Friday
    | Saturday

The week days