Reference

CronParser

The class behind Cron's static methods. It holds one expression, which is convenient when you want to ask several questions about the same schedule.

On this page
import { CronParser } from "cronbake";

const parser = new CronParser("0 30 9 * * 1-5");

parser.parse(); // { second: [0], minute: [30], hour: [9], ... }
parser.getNext(); // the next match
parser.getPrevious(); // the last match

The constructor doesn’t validate anything. An invalid expression throws when you first call a method.

In most code the static methods on Cron read better, and they do the same thing.

Methods

parse()

parse(): CronTime

Expands the expression or preset into the values each field matches. Throws if it’s invalid.

getNext()

getNext(from?: Date): Date

The first match after from, which defaults to now. Throws if the expression is invalid, from is an invalid date, or nothing matches within 400 years.

getPrevious()

getPrevious(from?: Date): Date

The last match before from, which defaults to now. Throws in the same cases as getNext().

esc

Try overlap, restore or timezone.