mtdowling/cron-expression
A PHP library for parsing and evaluating cron expressions. Check whether a schedule is due, get next/previous run dates, and iterate occurrences. Supports standard cron fields plus common extensions, useful for job schedulers and task runners.
Artisan scheduler and Carbon (via DateTime compatibility), reducing friction in adoption.Carbon (Laravel’s default datetime library) via DateTime conversion.CronExpression (if using older versions).exec('cron') calls.phpunit) to validate edge cases (e.g., * * * * * ? syntax, leap seconds).@yearly, @monthly).CronExpression facade).create_function).Carbon::setTestNow() in tests.CronExpression (if using Laravel 5.1+) or spatie/schedule for modern features.drushu/cron-expression (active fork) if maintenance is a priority.* * * * * *) be handled? (Current package may throw exceptions.)schedule:run with custom logic using this package (e.g., dynamic cron expressions from a database).crontab entries, Laravel Scheduler commands).* * * * * and validate next run time).Carbon interoperability:
use Cron\CronExpression;
$expression = CronExpression::factory('* * * * *');
$now = Carbon::now();
$nextRun = $expression->getNextRunDate($now);
Artisan commands to use the package.exec('cron') calls with in-memory parsing.Carbon facade.Illuminate\Console\Scheduling\Schedule to use custom logic:
$schedule->command('report:generate')->cron(fn () => CronExpression::factory('0 3 * * *')->isDue());
shouldRun() methods for delayed jobs.DateTime handling (e.g., new DateTime() instead of Carbon).$this->app->singleton(CronExpression::class, fn () => CronExpression::factory('* * * * *'));
Laravel\Tests\CronExpressionTest).Carbon to test timezone behavior.CronExpressionException).spatie/schedule) in 12–24 months.try {
$expression = CronExpression::factory($cronString);
} catch (\Cron\Exception\CronException $e) {
Log::error("Invalid cron expression: {$cronString}", ['exception' => $e]);
}
@hourly, 0 0 * * 0).CronExpressionCache class).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Invalid cron expression | Job never runs or runs unexpectedly | Validate expressions on input; use defaults. |
| PHP version incompatibility | Runtime errors | Test on target PHP version; use polyfills. |
| Timezone misconfiguration | Incorrect next-run calculations | Enforce UTC in tests; document timezone usage. |
| Package abandonment | Security/bug risks | Fork and maintain; plan migration to alternative. |
| High-frequency parsing (e.g., loop) | Performance degradation | Cache results; batch process expressions. |
* * * * * vs. @daily).How can I help you explore Laravel packages today?