[**Documentation**](../../../README)

***

[Documentation](../../../README) / [zerotal](../../README) / [scheduler](../README) / CronExpression

# Class: CronExpression

Defined in: [packages/scheduler/src/CronExpression.ts:9](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/scheduler/src/CronExpression.ts#L9)

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](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/scheduler/src/CronExpression.ts#L44)

#### Parameters

##### expression?

`string`

#### Returns

`CronExpression`

## Properties

### SEARCH\_HORIZON\_DAYS

> `readonly` `static` **SEARCH\_HORIZON\_DAYS**: `number`

Defined in: [packages/scheduler/src/CronExpression.ts:233](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/scheduler/src/CronExpression.ts#L233)

How far ahead [nextRunAfter](#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](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/scheduler/src/CronExpression.ts#L60)

#### Parameters

##### v

`string` \| `number`

#### Returns

`this`

***

### hour()

> **hour**(`v`): `this`

Defined in: [packages/scheduler/src/CronExpression.ts:64](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/scheduler/src/CronExpression.ts#L64)

#### Parameters

##### v

`string` \| `number`

#### Returns

`this`

***

### dayOfMonth()

> **dayOfMonth**(`v`): `this`

Defined in: [packages/scheduler/src/CronExpression.ts:68](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/scheduler/src/CronExpression.ts#L68)

#### Parameters

##### v

`string` \| `number`

#### Returns

`this`

***

### month()

> **month**(`v`): `this`

Defined in: [packages/scheduler/src/CronExpression.ts:72](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/scheduler/src/CronExpression.ts#L72)

#### Parameters

##### v

`string` \| `number`

#### Returns

`this`

***

### weekday()

> **weekday**(`v`): `this`

Defined in: [packages/scheduler/src/CronExpression.ts:76](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/scheduler/src/CronExpression.ts#L76)

#### Parameters

##### v

`string` \| `number`

#### Returns

`this`

***

### toString()

> **toString**(): `string`

Defined in: [packages/scheduler/src/CronExpression.ts:81](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/scheduler/src/CronExpression.ts#L81)

#### Returns

`string`

***

### matches()

> **matches**(`date?`): `boolean`

Defined in: [packages/scheduler/src/CronExpression.ts:126](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/scheduler/src/CronExpression.ts#L126)

#### Parameters

##### date?

`Date` = `...`

#### Returns

`boolean`

***

### nextRun()

> **nextRun**(`from?`): `Date` \| `null`

Defined in: [packages/scheduler/src/CronExpression.ts:151](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/scheduler/src/CronExpression.ts#L151)

#### Parameters

##### from?

`Date` = `...`

#### Returns

`Date` \| `null`

***

### isValid()

> `static` **isValid**(`expression`): `boolean`

Defined in: [packages/scheduler/src/CronExpression.ts:155](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/scheduler/src/CronExpression.ts#L155)

#### Parameters

##### expression

`string`

#### Returns

`boolean`

***

### nextRunAfter()

> `static` **nextRunAfter**(`expression`, `from?`): `Date` \| `null`

Defined in: [packages/scheduler/src/CronExpression.ts:206](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/scheduler/src/CronExpression.ts#L206)

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](#search_horizon_days) days.

***

### describe()

> `static` **describe**(`expression`): `string`

Defined in: [packages/scheduler/src/CronExpression.ts:247](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/scheduler/src/CronExpression.ts#L247)

#### Parameters

##### expression

`string`

#### Returns

`string`
