Skip to main content
zerotal

Documentation


Documentation / zerotal / scheduler / CronExpression

Class: CronExpression

Defined in: packages/scheduler/src/CronExpression.ts:9

Cron expression utility — builder, validator, human-readable describer and next-run calculator. Supports standard 5-field cron (m h dom mon dow) and tolerates an optional leading seconds field (6-field) for validation.

Field syntax: star, n, a-b, a-b with step, star with step, and comma-separated lists of any of those (e.g. 1,15,30 or 1-5).

Constructors

Constructor

new CronExpression(expression?): CronExpression

Defined in: packages/scheduler/src/CronExpression.ts:44

Parameters

expression?

string

Returns

CronExpression

Properties

SEARCH_HORIZON_DAYS

readonly static SEARCH_HORIZON_DAYS: number

Defined in: packages/scheduler/src/CronExpression.ts:233

How far ahead nextRunAfter looks. Four years and change, so a Feb-29 expression resolves to the next leap day instead of reporting that it never runs.

Methods

minute()

minute(v): this

Defined in: packages/scheduler/src/CronExpression.ts:60

Parameters

v

string | number

Returns

this


hour()

hour(v): this

Defined in: packages/scheduler/src/CronExpression.ts:64

Parameters

v

string | number

Returns

this


dayOfMonth()

dayOfMonth(v): this

Defined in: packages/scheduler/src/CronExpression.ts:68

Parameters

v

string | number

Returns

this


month()

month(v): this

Defined in: packages/scheduler/src/CronExpression.ts:72

Parameters

v

string | number

Returns

this


weekday()

weekday(v): this

Defined in: packages/scheduler/src/CronExpression.ts:76

Parameters

v

string | number

Returns

this


toString()

toString(): string

Defined in: packages/scheduler/src/CronExpression.ts:81

Returns

string


matches()

matches(date?): boolean

Defined in: packages/scheduler/src/CronExpression.ts:126

Parameters

date?

Date = ...

Returns

boolean


nextRun()

nextRun(from?): Date | null

Defined in: packages/scheduler/src/CronExpression.ts:151

Parameters

from?

Date = ...

Returns

Date | null


isValid()

static isValid(expression): boolean

Defined in: packages/scheduler/src/CronExpression.ts:155

Parameters

expression

string

Returns

boolean


nextRunAfter()

static nextRunAfter(expression, from?): Date | null

Defined in: packages/scheduler/src/CronExpression.ts:206

The first time at or after from that expression fires, or null when it never does within the search horizon.

The scan steps by minute, but skips a whole day at a time once the day itself cannot match — a day-scoped expression like 0 0 29 2 * would otherwise mean 533,000 minute probes to reach the next leap year, which is why a 370-day horizon reported "never runs" for a perfectly valid expression while burning ~320 ms of blocking CPU per call.

Parameters

expression

string

A 5- or 6-field cron expression.

from?

Date = ...

Search start; the result is strictly after this minute.

Returns

Date | null

The next firing time, or null for an invalid expression or one with no occurrence in the next SEARCH_HORIZON_DAYS days.


describe()

static describe(expression): string

Defined in: packages/scheduler/src/CronExpression.ts:247

Parameters

expression

string

Returns

string