You are here

function date_hours in Date 5.2

Same name and namespace in other branches
  1. 6.2 date_api.module \date_hours()
  2. 6 date_api.module \date_hours()
  3. 7.3 date_api/date_api.module \date_hours()
  4. 7 date_api/date_api.module \date_hours()
  5. 7.2 date_api/date_api.module \date_hours()

An array of hours.

Parameters

string $format:

$required: If not required, returned array will include a blank value.

Return value

an array of hours in the selected format.

1 call to date_hours()
date_parts_element in ./date_api_elements.inc
Create form elements for one or more date parts.

File

./date_api.module, line 294
This module will make the date API available to other modules. Designed to provide a light but flexible assortment of functions and constants, with more functionality in additional files that are not loaded unless other modules specifically include them.

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;
}