Package: effect
Module: Cron
Creates a Cron instance from time constraints.
When to use
Use to build a cron schedule from explicit sets of allowed time-field values.
Details
Constructs a cron schedule by specifying which seconds, minutes, hours,
days, months, and weekdays the schedule should match. Empty arrays leave a
time unit unrestricted. If only days or weekdays are restricted, that field
must match. When both are restricted, the default matches either field; set
and: true to require both fields to match. Weekdays range from 0 (Sunday)
to 7 (also Sunday). The constructor throws a RangeError when a field
contains a non-integer or out-of-range value.
Example (Creating schedules from constraints)
import { Cron } from "effect"
// Every day at midnight
const midnight = Cron.make({
minutes: [0],
hours: [0],
days: [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31
],
months: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
weekdays: [0, 1, 2, 3, 4, 5, 6]
})
// Every 15 minutes during business hours on weekdays
const businessHours = Cron.make({
minutes: [0, 15, 30, 45],
hours: [9, 10, 11, 12, 13, 14, 15, 16, 17],
days: [],
months: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
weekdays: [1, 2, 3, 4, 5] // Monday to Friday
})
See
parse for building a schedule from a cron expression stringSignature
declare const make: (values: { readonly seconds?: Iterable<number> | undefined; readonly minutes: Iterable<number>; readonly hours: Iterable<number>; readonly days: Iterable<number>; readonly months: Iterable<number>; readonly weekdays: Iterable<number>; readonly and?: boolean | undefined; readonly tz?: DateTime.TimeZone | undefined; }) => Cron
Since v2.0.0