PHP code example of thesis / cron-parser
1. Go to this page and download the library: Download thesis/cron-parser 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/ */
thesis / cron-parser example snippets
declare(strict_types=1);
use Thesis\Cron;
$parser = Cron\Parser::standard();
$time = $parser->parse('* * * * *');
echo $time->match(new \DateTimeImmutable('2025-01-29 00:00:00')); // true
declare(strict_types=1);
use Thesis\Cron;
$parser = Cron\Parser::standard();
$time = $parser->parse('* * * * *');
echo $time->tick(new \DateTimeImmutable('2025-01-29 00:00:00')); // 2025-01-29 00:01:00
declare(strict_types=1);
use Thesis\Cron;
$parser = Cron\Parser::standard();
$time = $parser->parse('* * * * *');
foreach ($time->iterator(new \DateTimeImmutable('2025-01-29 00:00:00'), iterations: 10) as $it) {
echo $it->format('Y-m-d H:i:s');
}
declare(strict_types=1);
use Thesis\Cron;
$parser = new Cron\Parser(
extension: new Cron\StandardParserExtension(),
replacers: [new Cron\AliasExpressionReplacer(['@secondly' => '* * * * * *'])],
normalizers: [new Cron\SundayExpressionNormalizer(), new Cron\WeekdayExpressionNormalizer()],
);
$time = $parser->parse('@secondly');
echo $time->match(new \DateTimeImmutable('2025-01-29 00:00:00')); // true
echo $time->match(new \DateTimeImmutable('2025-01-29 00:00:01')); // true
echo $time->match(new \DateTimeImmutable('2025-01-29 00:00:02')); // true