1 date.inc date_hours($format = 'H', $required = FALSE)

Constructs an array of hours.

Parameters

string $format: A date format string.

bool $required: (optional) If FALSE, the returned array will include a blank value. Defaults to FALSE.

Return value

array: An array of hours in the selected format.

File

core/includes/date.inc, line 310
Date API functions.

Code

function date_hours($format = 'H', $required = FALSE) {
  $hours = array();
  if ($format == 'h' || $format == 'g') {
    $min = 1;
    $max = 12;
  }
  else {
    $min = 0;
    $max = 23;
  }
  for ($i = $min; $i <= $max; $i++) {
    $hours[$i] = $i < 10 && ($format == 'H' || $format == 'h') ? "0$i" : $i;
  }
  $none = array('' => '');
  return !$required ? $none + $hours : $hours;
}