Skip to content
Parse and validate crontab expressions in PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/Cron
tests/Cron
.gitignore
.scrutinizer.yml
.travis.yml
LICENSE initial commit Sep 27, 2014
README.md
composer.json
phpunit.xml.dist

README.md

PHP Cron Expression Parser

Build Status Code Coverage License Latest Stable Version Total Downloads

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:

$expression = new \Cron\CronExpression('15,45 */2 * * *');
$isValid = $expression->isValid(); // returns true

Check whether a given point in time is matching a certain cron expression:

$expression = new \Cron\CronExpression('45 9 * * *');
$dt = new \DateTime('2014-05-18 09:45');
$isMatching = $expression->isMatching($dt); // returns true

Match an expression across different time zones:

$expression = new \Cron\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:

$expression = new \Cron\CronExpression('* * 13 * fri');
$when = $expression->getNext();

Supported PHP versions

PHP cron version
5.6 1.2.*
7.0 2.0.*
7.1 - 7.3 2.1.*

Changelog

version release notes
1.0.0 (2015-06-20) initial release
1.1.0 (2016-06-11) dropped PHP 5.4 support
1.2.0 (2016-12-11) added PHP 7.1 support
1.2.1 (2017-05-25) fixed #3
1.2.2 (2017-06-03) fixed #3, #4
2.0.0 (2017-11-30) dropped PHP 5.x, added PHP 7.2 support, added vendor namespace (closes #2)
2.1.0 (2018-12-08) dropped PHP 7.0, added PHP 7.3 support, updated PHPUnit dependency to 7.*
master dropped public setter methods, added testing with PHP 7.4snapshot
You can’t perform that action at this time.