Skip to content
docsv0.1.1

CronExpression

A standard 5-field cron expression (`minute hour day-of-month month day-of-week`) evaluated against a given instant. YAGNI on purpose: no seconds field, no `@daily`-style shorthands — just the 5 standard fields and 4 operator shapes a real deployment needs: `*` (any), `a,b` (list), `a-b` (range) and a step ("star, slash, N"). {@see TaskDefinition} is the only intended caller — it pairs an expression with the callback it gates. Every literal value and every range endpoint is bounds-checked against its field's valid range at construction — an out-of-range value (e.g. minute `99`, hour `25`) throws immediately instead of silently building an expression that can never become due. A range whose start is greater than its end (e.g. minute `5-1`) is likewise rejected at construction in every field — this package supports ascending ranges only, it does not infer a "wrap around the field's max" from a descending pair. The single deliberate exception is day-of-week: it additionally accepts `7` as the standard cron alias for Sunday (`0`), matching `crontab(5)`, so an otherwise-ascending range like `5-7` (5 <= 7) wraps to {5, 6, 0} (Fri, Sat, Sun) once `7` normalizes to `0` for matching.

CronExpression::__construct()

public function __construct(string $expression):

Parameters

Parameters of __construct()
NameTypeDescription
$expressionstring

Throws

InvalidArgumentException if `$expression` does not have exactly 5 whitespace-separated fields, any field uses a shape other than `*`, a comma list, a range, or a step (`*` followed by `/N`), or any literal value / range endpoint falls outside that field's valid range.

CronExpression::isDue()

public function isDue(DateTimeImmutable $now): bool

True when `$now` matches all 5 fields of this expression.

Parameters

Parameters of isDue()
NameTypeDescription
$nowDateTimeImmutable