hollodotme / crontab-expression
验证cron表达式并检查其到期日期的库
v0.1.0
2017-12-13 16:02 UTC
Requires
- php: >=7.1
- hollodotme/crontab-validator: ^2.0.0
- hollodotme/crontab-validator: ^2.0.0
Requires (Dev)
- tm/tooly-composer-script: ^1.0
This package is auto-updated.
Last update: 2024-08-29 04:58:47 UTC
README
CrontabExpression
描述
验证cron表达式并检查其到期日期的库
需求
- PHP >= 7.1
安装
composer require hollodotme/crontab-expression
使用方法
验证表达式
CrontabExpression
构造时对表达式进行验证。
如果您提供了一个无效的表达式,将抛出 hollodotme\CrontabValidator\Exceptions\InvalidExpressionException
。
如果您需要布尔验证cron表达式,请使用 hollodotme/crontab-validator。该 hollodotme/crontab-validator
包是此包(hollodotme/crontab-expression)的依赖项,因此您还可以单独使用验证器
<?php declare(strict_types=1); namespace YourVendor\YourProject; use hollodotme\CrontabValidator\CrontabValidator; $validator = new CrontabValidator(); if ($validator->isExpressionValid('*/10 6-21 * * 1-5')) { echo 'Expression is valid.'; } else { echo 'Expression is invalid.'; }
打印
Expression is valid.
检查日期是否满足表达式(表达式到期)
<?php declare(strict_types=1); namespace YourVendor\YourProject; use hollodotme\CrontabExpression\CrontabExpression; $expression = new CrontabExpression('*/10 6-21 * * 1-5'); echo $expression->isDue(new \DateTimeImmutable('2017-12-13 16:30:00')) ? 'Is due.' : 'Is not due.'; echo $expression->isDue(new \DateTimeImmutable('2017-12-10 16:30:00')) ? 'Is due.' : 'Is not due.'; # If you omit the $dateTime parameter, new \DateTimeImmutable() - current date - will be used. echo $expression->isDue() ? 'Depends on your current date & time. (DUE)' : 'Depends on your current date & time. (NOT DUE)';
打印
Is due.
Is not due.
Depends on your current date & time. (DUE|NOT DUE)
贡献
欢迎贡献,并将得到完全认可。请参阅贡献指南获取详细信息。