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, TimeStringMethods }
// 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 parameters:
- daysOfMonth
days of months
- daysOfWeek
days of week
- months
months
- times
times
- Note:
If
timesis 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 | Allowed Values |
|---|---|
second | 0-59 |
minute | 0-59 |
hour | 0-23 |
dayOfMonth | 1-31 |
month | 1-12 |
dayOfWeek | 0-7 (0 or 7 is Sunday) |
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 in month.
A field may be specified as an inclusive range, where the range endpoints
are separated by hyphen (-). For example, 5-7 in dayOfWeek.
A step may be appended to a range to include only incremental values, 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.
Names may be supplied for month and dayOfWeek either as full names
(e.g., Sunday and January) or their first 3 letters (e.g., Sun and
Jan). Names are case-insensitive and are not permitted in ranges.
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 * 10-12 *")
// Every hour on 1st and 15th of every month
val hourly = CronSchedule("0 * 1,15 * *")
// Every 15 seconds
val frequently = CronSchedule("*/15 * * * * *")
- Value parameters:
- fields
cron fields
- Returns:
cron schedule
- Throws:
- IllegalArgumentException
if fields cannot be parsed to a valid schedule