Provides CronSchedule
factory.
- Companion
- class
Type members
Value members
Concrete methods
Creates cron schedule with supplied fields.
Creates cron schedule with supplied fields.
Examples
import java.time.DayOfWeek.SUNDAY
import java.time.Month.{ OCTOBER, NOVEMBER, DECEMBER }
import little.time.CronSchedule
import little.time.Implicits.TimeStringType
// At noon on 1st and 15th in October thru December
val monthly = CronSchedule(
times = Seq("12:00".toLocalTime),
daysOfMonth = Seq(1, 15),
months = Seq(OCTOBER, NOVEMBER, DECEMBER))
// At 8 AM every Sunday
val weekly = CronSchedule(
times = Seq("08:00".toLocalTime),
daysOfWeek = Seq(SUNDAY)
)
// At 6 AM and 5 PM every day.
val daily = CronSchedule(
times = Seq("06:00".toLocalTime, "17:00".toLocalTime)
)
- Value Params
- daysOfMonth
days of months
- daysOfWeek
days of week
- months
months
- times
times
- Note
If
times
is empty, it is converted toSeq(LocalTime.MIDNIGHT)
.
Parses fields to cron schedule.
Parses fields to cron schedule.
Cron Schedule Format
The formatted cron schedule must be supplied as either 5 or 6 fields
separated by space. If only 5 fields are supplied, then second
defaults
to 0
.
Field | Required | Allowed Values |
---|---|---|
second | No | 0-59 |
minute | Yes | 0-59 |
hour | Yes | 0-23 |
dayOfMonth | Yes | 1-31 |
month | Yes | 1-12 or Jan-Dec |
dayOfWeek | Yes | 0-7 or Sun-Sat (Note: Sun is 0 or 7 ) |
A field may be specified as an asterisk (*
), which denotes first-last
based on field's allowed values.
A field may be specified as a list, where each value is separated by comma
(,
). For example, 10,11,12
or Oct,Nov,Dec
in month
.
A field may be specified as an inclusive range, where the range endpoints
are separated by hyphen (-
). For example, 5-7
or Fri-Sun
in
dayOfWeek
.
A step may be appended to a range to include only incremental values in
range, where range and step are supplied as <range>/<step>
. For example,
0-30/5
in minute
indicates every 5 minutes from 0 to 30, which
alternatively could be specified as 0,5,10,15,20,25,30
.
A step may also be appended to an asterisk to apply similar semantics. For
example, *``/15
in minute
indicates every 15 minutes.
Examples
// At 8 AM every Sunday
val weekly = CronSchedule("0 8 * * Sun")
// At noon every day in October thru December
val daily = CronSchedule("0 12 * Oct-Dec *")
// Every hour on 1st and 15th of every month
val hourly = CronSchedule("0 * 1,15 * *")
// Every 15 seconds
val frequently = CronSchedule("*/15 * * * * *")
- Value Params
- fields
cron fields
- Returns
cron schedule
- Throws
- IllegalArgumentException
if fields cannot be parsed to a valid schedule