Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Saturn handles POSIX cron schedules, which are defined here: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/crontab.html#tag_20_25_07.
A cron schedule is specified with five fields, each separated with at least one space. Each field can either be a wildcard (represented by an asterisk), or it can be one or more elements separated by commas. Each element can either be a number or a range, which is two numbers separated by a hyphen.
In order, the fields represent:
- Minute, between 0 and 59.
- Hour, between 0 and 23.
- Day, between 1 and 31.
- Month, between 1 and 12.
- Weekday, between 0 and 6 where 0 represents Sunday.
Here is a more graphical representation of the fields:
+--------- Minute | +------- Hour | | +----- Day | | | +--- Month | | | | +- Weekday | | | | | "* * * * *"
To get started, use fromText
to parse a Schedule
. Then
use toText
to render it again. To see if the Schedule
matches a certain time, use isMatch
. To get the next time that
matches a schedule, use nextMatch
.
>>>
:set -XOverloadedStrings
>>>
let Right schedule = fromText "* * * * *"
>>>
toText schedule
"* * * * *">>>
let utcTime = Data.Time.UTCTime (Data.Time.fromGregorian 1970 1 1) 0
>>>
isMatch utcTime schedule
True>>>
nextMatch utcTime schedule
Just 1970-01-01 00:01:00 UTC
Synopsis
- data Schedule
- everyMinute :: Schedule
- hourly :: Schedule
- daily :: Schedule
- weekly :: Schedule
- monthly :: Schedule
- yearly :: Schedule
- fromText :: Text -> Either ParseError Schedule
- fromLazyText :: Text -> Either ParseError Schedule
- fromString :: String -> Either ParseError Schedule
- toText :: Schedule -> Text
- toLazyText :: Schedule -> Text
- toString :: Schedule -> String
- isMatch :: UTCTime -> Schedule -> Bool
- nextMatch :: UTCTime -> Schedule -> Maybe UTCTime