mtdowling/cron-expression
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The "mtdowling/cron-expression" package is a PHP cron expression parser. It brings the ability to understand CRON scheduling definitions, making it possible to determine when a CRON expression is due to run, calculate the next or previous run dates, and even skip N number of matching dates. It supports a wide array of expressions including increments of ranges, intervals, list, and special characters like "W", "L" and "#", used for specific weekday and monthday calculations.
To use the "mtdowling/cron-expression" in your PHP project, you'll require to install it via composer by adding 'mtdowling/cron-expression' to your dependencies. Once installed, you can instantiate it by calling 'CronExpression::factory()' with your desired CRON expression as an argument. A few examples below illustrate its usage:
<?php
require_once '/vendor/autoload.php';
// Regular daily scheduling
$cron = Cron\CronExpression::factory('@daily');
// Check if the cron is due
$cron->isDue();
// Display the next run date
echo $cron->getNextRunDate()->format('Y-m-d H:i:s');
// Display the previous run date
echo $cron->getPreviousRunDate()->format('Y-m-d H:i:s');
// More complex cron expression
$cron = Cron\CronExpression::factory('3-59/15 2,6-12 */15 1 2-5');
echo $cron->getNextRunDate()->format('Y-m-d H:i:s');
// Get the run date two iterations into the future
$cron = Cron\CronExpression::factory('@daily');
echo $cron->getNextRunDate(null, 2)->format('Y-m-d H:i:s');
// Get the run date relative to a specific time
$cron = Cron\CronExpression::factory('@monthly');
echo $cron->getNextRunDate('2010-01-12 00:00:00')->format('Y-m-d H:i:s');
The documentation for the "mtdowling/cron-expression" package can be found on its GitHub page at "https://github.com/mtdowling/cron-expression". The readme file in the main repository is a comprehensive source of information, providing all the necessary details on usage, CRON expression structure, requirements, and installation instructions.