\d{1,2}):(?\d{2})\s*-\s*(?\d{1,2}):(?\d{2})\s*$/', $schedule_period, $matches)) { throw $incorrect_schedule_exception; } $from_h = $matches['from_h']; $from_m = $matches['from_m']; $to_h = $matches['to_h']; $to_m = $matches['to_m']; $day_period_from = SEC_PER_HOUR * $from_h + SEC_PER_MIN * $from_m; $day_period_to = SEC_PER_HOUR * $to_h + SEC_PER_MIN * $to_m; if ($from_m > 59 || $to_m > 59 || $day_period_from >= $day_period_to || $day_period_to > SEC_PER_DAY) { throw $incorrect_schedule_exception; } $schedule[] = [ 'period_from' => SEC_PER_DAY * $weekday + $day_period_from, 'period_to' => SEC_PER_DAY * $weekday + $day_period_to ]; } } if (!$schedule) { throw new InvalidArgumentException(_s('Incorrect schedule: %1$s.', _('cannot be empty'))); } return $schedule; } }