(cron: Cron, now?: DateTime.DateTime.Input): IterableIterator<Date>Returns an infinite iterator that yields dates matching the Cron schedule.
When to use
Use to lazily iterate future occurrences of a cron schedule.
Details
The iterator generates an infinite sequence of dates when the cron schedule should trigger, starting after the specified date/time or after the current time when no date is provided.
Example (Iterating scheduled occurrences)
import { Cron, Result } from "effect"
const cron = Result.getOrThrow(Cron.parse("0 0 9 * * 1-5")) // 9 AM weekdays
// Get first 5 occurrences
const iterator = Cron.sequence(cron, new Date("2023-01-01"))
const next5 = Array.from({ length: 5 }, () => iterator.next().value)
console.log(next5)
// [Mon Jan 02 2023 09:00:00, Tue Jan 03 2023 09:00:00, ...]export const const sequence: (
cron: Cron,
now?: DateTime.DateTime.Input
) => IterableIterator<Date>
Returns an infinite iterator that yields dates matching the Cron schedule.
When to use
Use to lazily iterate future occurrences of a cron schedule.
Details
The iterator generates an infinite sequence of dates when the cron schedule
should trigger, starting after the specified date/time or after the current
time when no date is provided.
Example (Iterating scheduled occurrences)
import { Cron, Result } from "effect"
const cron = Result.getOrThrow(Cron.parse("0 0 9 * * 1-5")) // 9 AM weekdays
// Get first 5 occurrences
const iterator = Cron.sequence(cron, new Date("2023-01-01"))
const next5 = Array.from({ length: 5 }, () => iterator.next().value)
console.log(next5)
// [Mon Jan 02 2023 09:00:00, Tue Jan 03 2023 09:00:00, ...]
sequence = function*(cron: Cron(parameter) cron: {
tz: Option.Option<DateTime.TimeZone>;
seconds: ReadonlySet<number>;
minutes: ReadonlySet<number>;
hours: ReadonlySet<number>;
days: ReadonlySet<number>;
months: ReadonlySet<number>;
weekdays: ReadonlySet<number>;
and: boolean;
first: { readonly second: number; readonly minute: number; readonly hour: number; readonly day: number; readonly month: number; readonly weekday: number };
last: { readonly second: number; readonly minute: number; readonly hour: number; readonly day: number; readonly month: number; readonly weekday: number };
next: { readonly second: ReadonlyArray<number | undefined>; readonly minute: ReadonlyArray<number | undefined>; readonly hour: ReadonlyArray<number | undefined>; readonly day: ReadonlyArray<number | undefined>; readonly month: ReadonlyArray<numb…;
prev: { readonly second: ReadonlyArray<number | undefined>; readonly minute: ReadonlyArray<number | undefined>; readonly hour: ReadonlyArray<number | undefined>; readonly day: ReadonlyArray<number | undefined>; readonly month: ReadonlyArray<numb…;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
cron: Cron, now: DateTime.DateTime.Input | undefinednow?: import DateTimeDateTime.DateTime.type DateTime.Input = string | number | DateTime.DateTime | Partial<DateTime.DateTime.Parts> | DateTime.DateTime.Instant | DateTime.DateTime.InstantWithZone | DateInput accepted by DateTime.make, DateTime.makeUnsafe, and the zoned
constructors.
Details
Includes existing DateTime values, partial date parts, epoch-millisecond
objects, epoch milliseconds, JavaScript Date instances, and parseable date
strings.
Input): interface IterableIterator<T, TReturn = any, TNext = any>Describes a user-defined
Iterator
that is also iterable.
IterableIterator<Date> {
while (true) {
yield now: DateTime.DateTime.Input | undefinednow = const next: (
cron: Cron,
now?: DateTime.DateTime.Input
) => Date
Returns the next scheduled date/time for the given Cron instance.
When to use
Use to find the next occurrence of a cron schedule after a specific date/time
or after the current time.
Details
Searches for the next date and time when the cron schedule should trigger,
starting after the specified date/time or after the current time when no
date is provided.
Example (Finding the next occurrence)
import { Cron, Result } from "effect"
const cron = Result.getOrThrow(Cron.parse("0 0 4 8-14 * *"))
// Get next run after a specific date
const after = new Date("2021-01-01T00:00:00Z")
const nextRun = Cron.next(cron, after)
console.log(nextRun) // 2021-01-08T04:00:00.000Z
// Get next run from current time
const nextFromNow = Cron.next(cron)
console.log(nextFromNow) // Next occurrence from now
next(cron: Cron(parameter) cron: {
tz: Option.Option<DateTime.TimeZone>;
seconds: ReadonlySet<number>;
minutes: ReadonlySet<number>;
hours: ReadonlySet<number>;
days: ReadonlySet<number>;
months: ReadonlySet<number>;
weekdays: ReadonlySet<number>;
and: boolean;
first: { readonly second: number; readonly minute: number; readonly hour: number; readonly day: number; readonly month: number; readonly weekday: number };
last: { readonly second: number; readonly minute: number; readonly hour: number; readonly day: number; readonly month: number; readonly weekday: number };
next: { readonly second: ReadonlyArray<number | undefined>; readonly minute: ReadonlyArray<number | undefined>; readonly hour: ReadonlyArray<number | undefined>; readonly day: ReadonlyArray<number | undefined>; readonly month: ReadonlyArray<numb…;
prev: { readonly second: ReadonlyArray<number | undefined>; readonly minute: ReadonlyArray<number | undefined>; readonly hour: ReadonlyArray<number | undefined>; readonly day: ReadonlyArray<number | undefined>; readonly month: ReadonlyArray<numb…;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
cron, now: DateTime.DateTime.Input | undefinednow)
}
}