function date_hours in Date 7.2
Same name and namespace in other branches
- 5.2 date_api.module \date_hours()
- 6.2 date_api.module \date_hours()
- 6 date_api.module \date_hours()
- 7.3 date_api/date_api.module \date_hours()
- 7 date_api/date_api.module \date_hours()
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.
1 call to date_hours()
- date_parts_element in date_api/
date_api_elements.inc - Creates form elements for one or more date parts.
File
- date_api/
date_api.module, line 1418 - This module will make the date API available to other modules.
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;
}