mike-tralala/cron-expression
Composer 安装命令:
composer require mike-tralala/cron-expression
包简介
A library to use cron expressions in PHP
README 文档
README
This cron-expression library can parse cron expressions like * * * * * and check if
it is due or not. You are also able to determine the next or previous running dates.
This parser can handle anything the normal cron syntax accepts. with 1 exception and that are the named constructs (e.g. mon-thu or jan-dec).
Installing
Add the dependency to your project:
composer require mike-tralala/cron-expression
Usage
<?php require_once __DIR__ . '/vendor/autoload.php'; use MikeTralala\CronExpression\Expression\DueDateCalculator; use MikeTralala\CronExpression\Expression\Expression; // Works with predefined definitions $expression = new Expression(Expression::WEEKLY); $expression->isDue(); $expression = new Expression(Expression::MINUTELY); $expression->isDue(); // Works with complex definitions $expression = new Expression('10-40/10 0 */5 1 4,5'); $expression->isDue(); // Calculating next running date $calculator = new DueDateCalculator(); $expression = new Expression('*/2 * * * *'); $dueDates = $calculator->getNextDueDates($expression, 5, \DateTime::createFromFormat('Y-m-d H:i', '2018-01-01 00:00')); echo $expression . PHP_EOL; foreach ($dueDates as $dueDate) { echo $dueDate->format('Y-m-d H:i') . PHP_EOL; } // Output: // */2 * * * * // 2018-01-01 00:00 // 2018-01-01 00:02 // 2018-01-01 00:04 // 2018-01-01 00:06 // 2018-01-01 00:08
CRON Expressions
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 - 6) (Sunday=0)
| | | +---------- month (1 - 12)
| | +--------------- day of month (1 - 31)
| +-------------------- hour (0 - 23)
+------------------------- min (0 - 59)
Requirements
- PHP 5.5+
- PHPUnit is required to run the unit tests
- Composer is required to run the unit tests
统计信息
- 总下载量: 1.05k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-04-01