Skip to content
Français

createCronSchedule

import { createCronSchedule } from "@elie-laloum/outpost";

Parse a five-field cron expression, or a macro such as @daily, evaluated in an IANA time zone (UTC by default). The frozen result computes slots with next() and previous() and publishes nothing. Construction rejects invalid fields, unknown time zones and expressions without any occurrence.

Complete example and detailed rules.

  • expressionRequired
    string
    Five fields (minute, hour, day of month, month, day of week) with lists, ranges, steps and three-letter month or weekday names, or a macro such as @hourly or @daily; at most 256 characters. Weekday 0 and 7 are Sunday, and when both day fields are restricted, a day matching either one matches.
  • optionsOptional
    CronOptions | undefined
    Evaluation options; omit them to evaluate in UTC.
  • options.timeZoneOptional
    string | undefined
    IANA time zone whose wall-clock time the expression describes, such as Europe/Paris; defaults to UTC.

CronSchedule

export declare function createCronSchedule(
  expression: string,
  options?: CronOptions,
): CronSchedule;