public static function DateHelper::hours

public static DateHelper::hours($format = 'H', $required = FALSE)

Constructs an array of hours.

Parameters

string $format: (optional) A date format string that indicates the format to use for the hours. Defaults to 'H'.

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/lib/Drupal/Core/Datetime/DateHelper.php, line 351

Class

DateHelper
Defines Gregorian Calendar date values.

Namespace

Drupal\Core\Datetime

Code

public static function 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++) {
    $formatted = ($format == 'H' || $format == 'h') ? DrupalDateTime::datePad($i) : $i;
    $hours[$i] = $formatted;
  }
  $none = array('' => '');
  return !$required ? $none + $hours : $hours;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Datetime!DateHelper.php/function/DateHelper::hours/8.1.x