next(); if (str_contains($match, '^')) { return false; } return true; } public function next(): string { $time = time(); return sprintf('%s-%s-%s %s:%s:%s %s', date('Y'), $this->format($time, $this->month, 'm', 'month'), $this->format($time, $this->day, 'd', 'day'), $this->format($time, $this->hour, 'H', 'hour'), $this->format($time, $this->minute, 'i', 'minute'), $this->format($time, $this->second, 's', 'second'), $this->format($time, $this->week, 'N'), ); } /** * @param int $startTime * @param string $text * @param string $match * @param string|null $format * @return string */ private function format(int &$startTime, string $text, string $match, ?string $format = null): string { $time = date($match); if ($text == '*' || $text == '*/1') { return $time; } if (str_contains($text, ',')) { $explode = explode(',', $text); sort($explode, SORT_NUMERIC); if (in_array($time, $explode)) { return $explode[array_search($time, $explode) + 1]; } return '^'; } if (str_contains($text, '-')) { $explode = explode('-', $text); if ($time >= $explode[0] && $time <= $explode[1]) { return intval($time); } return '^'; } if (str_contains($text, '/')) { $explode = explode('/', $text); if ($time % $explode[1] !== 0) { return '^'; } if ($explode[0] != '*') { return $explode[0] == $text ? $time : '^'; } return $time; } return $time == $text ? $time : '^'; } } //$date = date('Y-m-d H:i:s'); //var_dump(date('Y-m-d H:i:s', strtotime('+10 month', strtotime($date)))); //var_dump(date('Y-m-d H:i:s', strtotime('+10 day', strtotime($date)))); //var_dump(date('Y-m-d H:i:s', strtotime('+10 hour', strtotime($date)))); //var_dump(date('Y-m-d H:i:s', strtotime('+10 minute', strtotime($date)))); //var_dump(date('Y-m-d H:i:s', strtotime('+10 second', strtotime($date)))); //var_dump(date('Y-m-d H:i:s', strtotime('+10 week', strtotime($date)))); $c = new Crontab(); while (true) { var_dump($c->next()); sleep(1); }