PHP code example of adhocore / cron-expr

1. Go to this page and download the library: Download adhocore/cron-expr 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/ */

    

adhocore / cron-expr example snippets


use Ahc\Cron\Expression;
use Ahc\Cron\Normalizer;

Expression::isDue('@always');
Expression::isDue(Normalizer::HOURLY, '2015-01-01 00:00:00');
Expression::isDue('*/20 * * * *', new DateTime);
Expression::isDue('5-34/4 * * * *', time());

// Dont like static calls? Below is possible too!
$expr = new Expression;
$expr->isCronDue('*/1 * * * *', time());

use Ahc\Cron\Expression;

$jobs = [
    'job1' => '*/2 */2 * * *',
    'job1' => '* 20,21,22 * * *',
    'job3' => '7-9 * */9 * *',
    'job4' => '*/5 * * * *',
    'job5' => '@5minutes',     // equivalent to job4 (so it is due if job4 is due)
    'job6' => '7-9 * */9 * *', // exact same as job3 (so it is due if job3 is due)
];

// The second param $time can be used same as above: null/time()/date string/DateTime
$dues = Expression::getDues($jobs, '2015-08-10 21:50:00');
// ['job1', 'job4', 'job5']

// Dont like static calls? Below is possible too!
$expr = new Expression;
$dues = $expr->filter($jobs, time());