Index

cCronField

MMO\core\helpers · 1 symbol · generated 5 Oct 2026

enum

cCronField

cCronField.php:73

CRON Expressions ================

enum MMO\core\helpers\cCronField: int
Namespace
MMO\core\helpers
A CRON expression is a string representing the schedule for a particular command to execute. The parts of a CRON schedule are as follows: ``` * * * * - - - - - | | | | | | | | | | | | | | +----- day of week (0-7) (Sunday = 0 or 7) (or SUN-SAT) | | | +--------- month (1-12) (or JAN-DEC) | | +------------- day of month (1-31) | +----------------- hour (0-23) +--------------------- minute (0-59) ``` Each part of expression can also use wildcard, lists, ranges and steps: - wildcard - match always - `* * * * *` - At every minute. - day of week and day of month also support `?`, an alias to `*` - lists - match list of values, ranges and steps - e.g. `15,30 * * * *` - At minute 15 and 30. - ranges - match values in range - e.g. `1-9 * * * *` - At every minute from 1 through 9. - steps - match every nth value in range - e.g. `* /5 * * * *` - At every 5th minute. - e.g. `0-30/5 * * * *` - At every 5th minute from 0 through 30. - combinations - e.g. `0-14,30-44 * * * *` - At every minute from 0 through 14 and every minute from 30 through 44. You can also use macro instead of an expression: - `@yearly`, `@annually` - At 00:00 on 1st of January. (same as `0 0 1 1 * `) - `@monthly` - At 00:00 on day-of-month 1. (same as `0 0 1 * *`) - `@weekly` - At 00:00 on Sunday. (same as `0 0 * * 0`) - `@daily`, `@midnight` - At 00:00. (same as `0 0 * * *`) - `@hourly` - At minute 0. (same as `0 * * * *`) Day of month extra features: - nearest weekday - weekday (Monday-Friday) nearest to the given day ` * * 15W * *` - At every minute on a weekday nearest to the 15th. - If you were to specify `15W` as the value, the meaning is: "the nearest weekday to the 15th of the month" So if the 15th is a Saturday, the trigger will fire on Friday the 14th. If the 15th is a Sunday, the trigger will fire on Monday the 16th. If the 15th is a Tuesday, then it will fire on Tuesday the 15th. - However, if you specify `1W` as the value for day-of-month, and the 1st is a Saturday, the trigger will fire on Monday the 3rd, as it will not 'jump' over the boundary of a month's days. - last day of the month ` * * L * *` - At every minute on a last day-of-month. - last day of the month with offset ` * * L-3 * *` - At every minute on 3 days before the last day-of-month. - last weekday of the month ` * * LW * *` - At every minute on a last weekday. Day of week extra features: - nth day ` * * * * 7#4` - At every minute on 4th Sunday. Every day of week repeats 4 - 5 times a month . To target the last one, use "last day" feature instead . - last day `* * * * 7L` - At every minute on the last Sunday.

Index

ALIAS_DAYS
ALIAS_MONTHS
DayOfMonthDay of the month (1-31)
DayOfWeekDay of the week day of week (0-6 : Sunday - Saturday), or (1-7 : Monday - Sunday), or (Sun-Sat)
HourHours (0-23)
MinuteMinutes (0-59)
MonthMonth (1-12) or (JAN-DEC)
name readonly
value readonly
cases() static
check($date, $range)Check if a date is within the range of the current field
describe($value)Turn a field expression into a list of human-readable fragments (e.g.
from($value) static
isValid($value)Tells if a full field expression is valid: a wildcard (*/?), a comma-separated list, a step (/N), a range (start-end), or a single value (isValueValid) -- any combination thereof.
isValueValid($value)Test if a SINGLE value (not a list/range/step expression -- see isValid for that) is valid for this field: a plain number within limits, a day/month name alias, or (for DayOfMonth/DayOfWe…
limits()
range($value)Parse a field expression into the explicit list of values (or special tokens like 'L'/'15W') it allows.
tryFrom($value) static

Constants7

ALIAS_DAYS

const ALIAS_DAYS = […14 items]

ALIAS_MONTHS

const ALIAS_MONTHS = […23 items]

DayOfMonth

Day of the month (1-31)

const DayOfMonth = MMO\core\helpers\cCronField::DayOfMonth

DayOfWeek

Day of the week day of week (0-6 : Sunday - Saturday), or (1-7 : Monday - Sunday), or (Sun-Sat)

const DayOfWeek = MMO\core\helpers\cCronField::DayOfWeek

Hour

Hours (0-23)

const Hour = MMO\core\helpers\cCronField::Hour

Minute

Minutes (0-59)

const Minute = MMO\core\helpers\cCronField::Minute

Month

Month (1-12) or (JAN-DEC)

const Month = MMO\core\helpers\cCronField::Month

Properties2

name

readonly
readonly string $name
Type
string

value

readonly
readonly int $value
Type
int

Methods9

cases()

static
static function cases(): array
returnsarray

check($date, $range)

cCronField.php:216

Check if a date is within the range of the current field

function check(DateTimeInterface $date, array|string|null $range): bool
$dateDateTimeInterface
$rangearray | string | nulla raw field expression (parsed via range), an already-parsed array, or null (always matches)
returnsbool
cCronField::Minute->check(new DateTime('2024-01-01 00:15:00'), '15,30'); // truecCronField::DayOfMonth->check(new DateTime('2024-06-14'), '15W'); // true: nearest weekday to the 15th (a Saturday in June 2024) is Friday the 14th

describe($value)

cCronField.php:343

Turn a field expression into a list of human-readable fragments (e.g. for building a sentence like "at minute 0, every 5 of [10-20], last day").

function describe(string $value): array
$valuestring
returnsarray
cCronField::Minute->describe('0,5,10,15,20'); // ['every 5 of [0-20]']cCronField::DayOfMonth->describe('L'); // ['last day']cCronField::DayOfMonth->describe('15W'); // ['closest week day to the 15th']

from($value)

static
static function from(string|int $value): static
$valuestring | int
returnsstatic

isValid($value)

cCronField.php:182

Tells if a full field expression is valid: a wildcard (*/?), a comma-separated list, a step (/N), a range (start-end), or a single value (isValueValid) -- any combination thereof.

function isValid(array|string|int $value): bool
$valuearray | string | int
returnsbool
cCronField::Minute->isValid('0-30/5'); // truecCronField::Minute->isValid('15,30,90'); // false: 90 is out of range

isValueValid($value)

cCronField.php:153

Test if a SINGLE value (not a list/range/step expression -- see isValid for that) is valid for this field: a plain number within limits, a day/month name alias, or (for DayOfMonth/DayOfWeek) one of the special forms documented on this enum (L, L-3, LW, 15W, 7#4, 7L).

function isValueValid(string|int $value): bool
$valuestring | int
returnsbool
cCronField::DayOfMonth->isValueValid('15W'); // truecCronField::DayOfMonth->isValueValid('15Wgarbage'); // falsecCronField::Month->isValueValid('jan'); // true

limits()

cCronField.php:133
function limits(): array
returnsarrayint, 1: int} [min, max] for this field, e.g. [0, 59] for Minute

range($value)

cCronField.php:275

Parse a field expression into the explicit list of values (or special tokens like 'L'/'15W') it allows.

function range(string $value): ?array
$valuestring
returnsnull | array
throwsif $value (or any part of it) is not valid for this field
cCronField::Minute->range('0-30/5'); // [0, 5, 10, 15, 20, 25, 30]cCronField::Minute->range('15,30'); // [15, 30]cCronField::DayOfWeek->range('mon-fri'); // [1, 2, 3, 4, 5]

tryFrom($value)

static
static function tryFrom(string|int $value): ?static
$valuestring | int
returnsnull | static