/** * Next run datetime * * @param mixed $datetime * @return string */ public function next_run_date($datetime = null) { $result = null; if (empty($datetime)) { $datetime = format::now('unix'); } else { if (!is_numeric($datetime)) { $datetime = strtotime($datetime); } } $parts = format::datetime_parts($datetime); for ($year = $parts['year']; $year <= self::$slot_stats[6]['max']; $year++) { // check if we are in range if (!(in_array('*', $this->parsed_expression['year']) || in_array($year, $this->parsed_expression['year']))) { continue; } for ($month = 1; $month <= 12; $month++) { // check if we are in range if (!(in_array('*', $this->parsed_expression['month']) || in_array($month, $this->parsed_expression['month']))) { continue; } for ($day = 1; $day <= 31; $day++) { // check if we are in range if (!(in_array('*', $this->parsed_expression['day']) || in_array($day, $this->parsed_expression['day']))) { continue; } // check weekday $weekday = date('w', mktime(0, 0, 0, $month, $day, $year)); if (!(in_array('*', $this->parsed_expression['weekday']) || in_array($weekday, $this->parsed_expression['weekday']))) { continue; } // loop through hours for ($hour = 0; $hour <= 23; $hour++) { // check if we are in range if (!(in_array('*', $this->parsed_expression['hour']) || in_array($hour, $this->parsed_expression['hour']))) { continue; } // loop though minutes for ($minute = 0; $minute <= 59; $minute++) { $date = mktime($hour, $minute, 0, $month, $day, $year); if ($date < $datetime) { continue; } else { // check if we are in range if (!(in_array('*', $this->parsed_expression['minute']) || in_array($minute, $this->parsed_expression['minute']))) { continue; } // check the rest $result = format::datetime($date); goto exit1; } } } } } } exit1: return $result; }