dragonmantank/cron-expression
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
webmozart/assert | 1.11.0 | 19.58 kB | MIT | prod |
Dragonmantank/cron-expression is a powerful tool that gives PHP the ability to handle CRON expressions. This PHP cron expression parser can interpret a CRON expression, determine if it's due for execution, calculate the next and previous run dates of the expression, and even manage complex expressions involving ranges, lists, weekdays, and more. It's great for scheduling tasks and events far into the future or the past.
To use the Dragonmantank/cron-expression package, first add it to your PHP project using composer command composer require dragonmantank/cron-expression
. After installing the package, you can utilize it in your PHP code. Here's an example:
<?php
require_once '/vendor/autoload.php';
// For predefined scheduling definitions
$cron = new Cron\CronExpression('@daily');
$cron->isDue();
echo $cron->getNextRunDate()->format('Y-m-d H:i:s');
echo $cron->getPreviousRunDate()->format('Y-m-d H:i:s');
// For handling complex expressions
$cron = new Cron\CronExpression('3-59/15 6-12 */15 1 2-5');
echo $cron->getNextRunDate()->format('Y-m-d H:i:s');
// To calculate a run date two iterations ahead
$cron = new Cron\CronExpression('@daily');
echo $cron->getNextRunDate(null, 2)->format('Y-m-d H:i:s');
// To calculate a run date based on a specific time
$cron = new Cron\CronExpression('@monthly');
echo $cron->getNextRunDate('2010-01-12 00:00:00')->format('Y-m-d H:i:s');
The main source of documentation for the Dragonmantank/cron-expression package can be found on its GitHub page, and in the readme file of the package. The readme file explains the functions, usage details, installation procedure, and contains examples to assist users. Additionally, the creator's blog post provides further insight into the fork's features and capabilities. Keep in mind the information about the format of cron expressions, and the predefined scheduling definitions (macros), while using this package.