Schedule/CronNextRun.php

synaplan · backend/src/Service/SavedTask/Schedule/CronNextRun.php · php · Apache-2.0
automation, tag:knn-classified

Calculates the next execution time for a 5-field cron expression, useful for task schedulers or job systems.

// Source: https://github.com/metadist/synaplan | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
<?php

declare(strict_types=1);

namespace App\Service\SavedTask\Schedule;

/**
 * Next-run calculator for a 5-field cron expression (min hour day month weekday).
 */
final class CronNextRun
{
    public function next(string $expression, \DateTimeImmutable $from, \DateTimeZone $tz): \DateTimeImmutable
    {
        $parts = preg_split('/\s+/', trim($expression)) ?: [];
        if (5 !== count($parts)) {
            throw new \InvalidArgumentException('Cron expression must have 5 fields');
        }

        $localNow = $from->setTimezone($tz);
        $local = $localNow->setTime((int) $

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key