Documentations › mmo.core › php › helpers CronExp MMO\core\helpers · 1 symbol · generated 30 Sep 2026
A parsed 5-field cron expression (minute hour dayOfMonth month dayOfWeek), used by Cron to schedule jobs. dayOfMonth/dayOfWeek default to '?' ("don't care" -- either one being '?' means only the other constrains the match; standard cron convention).
class MMO\core\helpers\CronExp
implements Stringable Namespace MMO\core\helpersImplements Stringable $exp = CronExp::From('@daily'); // '0 0 * * *'
$exp->check(new DateTime('2024-01-01 00:00:00')); // true
$exp->check(new DateTime('2024-01-01 00:01:00')); // false
Index ALIAS static Named shorthand expressions recognized by From , e.g. dayOfMonth dayOfWeek hour minute month check($date) describe() From($value) static Parse a cron expression, either a raw 5-field string or a registered $ALIAS . FromDate($date) static Build an expression that matches exactly one point in time (to the minute): $date's own minute/hour/day-of-month/month, with dayOfWeek left as '?'. GetAlias($alias) static isValid() SetAlias($alias, $value) static Register (or, with $value null, remove) a named alias for From to recognize. __construct($minute, $hour, $dayOfMonth, $month, $dayOfWeek) __toString()
Properties6 Named shorthand expressions recognized by From , e.g. '@daily' => '0 0 * * *'.
static array $ALIAS = […7 items] Type array string $dayOfMonth Type string string $dayOfWeek Type string string $hour Type string string $minute Type string string $month Type string Methods9 function check(DateTimeInterface $date): bool function describe(): string returns string a human-readable description of the schedule (e.g. "every day at midnight") throws always, until it is
Parse a cron expression, either a raw 5-field string or a registered $ALIAS .
static function From(string $value): static $value string e.g. '0 0 * * *', or '@daily' returns static throws if $value starts with '@' but isn't a registered alias
CronExp::From('0 5 * * *'); CronExp::From('@daily');
Build an expression that matches exactly one point in time (to the minute): $date's own minute/hour/day-of-month/month, with dayOfWeek left as '?'.
static function FromDate(DateTimeInterface|string $date): static CronExp::FromDate(new DateTime('2024-03-15 14:30:00')); // '30 14 15 03 *'
static function GetAlias(string $alias): ?string $alias string returns null | string the alias's expansion, or null if $alias isn't registered
function isValid(): bool returns bool true if every field is a syntactically valid cCronField expression
Register (or, with $value null, remove) a named alias for From to recognize.
static function SetAlias(string $alias, ?string $value): void $alias string e.g. '@custom' $value null | string the 5-field cron expression it expands to, or null to remove the alias returns void
CronExp::SetAlias('@custom', '0 5 * * *');
__construct($minute, $hour, $dayOfMonth, $month, $dayOfWeek) CronExp.php:91 function __construct(
string $minute = '*',
string $hour = '*',
string $dayOfMonth = '?',
string $month = '*',
string $dayOfWeek = '?'
) function __toString(): string returns string the raw 5-field expression, e.g. '0 0 * * *'