poliander / cron
Standard (V7) compliant crontab expression parser/validator with support for time zones
Installs: 152 678
Dependents: 2
Suggesters: 0
Security: 0
Stars: 63
Watchers: 4
Forks: 10
Open Issues: 0
Requires
- php: 8.1.* || 8.2.* || 8.3.*
Requires (Dev)
- phpunit/phpunit: ~10.0
README
Standard (V7) compliant crontab expression parser/validator with support for time zones; see "man 5 crontab" for possible expressions.
Installation
Using composer, add a requirement for poliander/cron
to your composer.json
file:
composer require poliander/cron
Examples
Validate a certain crontab expression:
use Poliander\Cron\CronExpression; $expression = new CronExpression('15,45 */2 * * *'); $isValid = $expression->isValid(); // returns true
Check whether a given point in time is matching a certain cron expression:
use Poliander\Cron\CronExpression; $expression = new CronExpression('45 9 * * *'); $dt = new \DateTime('2014-05-18 09:45'); $isMatching = $expression->isMatching($dt); // returns true
Match an expression across different time zones:
use Poliander\Cron\CronExpression; $expression = new CronExpression('45 9 * * *', new DateTimeZone('Europe/Berlin')); $dt = new \DateTime('2014-05-18 08:45', new DateTimeZone('Europe/London')); $isMatching = $expression->isMatching($dt); // returns true
Calculate next timestamp matching a Friday, the 13th:
use Poliander\Cron\CronExpression; $expression = new CronExpression('* * 13 * fri'); $when = $expression->getNext();