You are here

protected function JobSchedulerCronTab::nextHour in Job Scheduler 8.3

Same name and namespace in other branches
  1. 8.2 src/JobSchedulerCronTab.php \Drupal\job_scheduler\JobSchedulerCronTab::nextHour()

Finds the next available hour within the same day.

Parameters

array $date: Date array with: 'mday', 'mon', 'year', 'hours', 'minutes'.

Return value

array|false A date array, or false if there was an error.

1 call to JobSchedulerCronTab::nextHour()
JobSchedulerCronTab::nextDate in src/JobSchedulerCronTab.php
Finds the next occurrence within the next year as a date array.

File

src/JobSchedulerCronTab.php, line 227

Class

JobSchedulerCronTab
Class for job scheduler crontab.

Namespace

Drupal\job_scheduler

Code

protected function nextHour(array $date) {
  $cron = $this->cron;
  while ($cron['hours']) {
    $hour = array_shift($cron['hours']);

    // Current hour; next minute.
    if ($date['hours'] == $hour) {
      foreach ($cron['minutes'] as $minute) {
        if ($date['minutes'] < $minute) {
          $date['hours'] = $hour;
          $date['minutes'] = $minute;
          return $date;
        }
      }
    }
    elseif ($date['hours'] < $hour) {
      $date['hours'] = $hour;
      $date['minutes'] = reset($cron['minutes']);
      return $date;
    }
  }
  return FALSE;
}