PHP code example of mike-tralala / cron-expression

1. Go to this page and download the library: Download mike-tralala/cron-expression library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mike-tralala / cron-expression example snippets




ikeTralala\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