You are here

public static function PersianDateHelper::hours in Persian Date for Drupal 8 8.4

Same name and namespace in other branches
  1. 8 src/PersianDateHelper.php \Drupal\persian_date\PersianDateHelper::hours()

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.

Overrides DateHelper::hours

File

src/PersianDateHelper.php, line 335

Class

PersianDateHelper

Namespace

Drupal\persian_date

Code

public static function hours($format = 'H', $required = FALSE) {
  $hours = [];
  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 = [
    '' => '',
  ];
  return !$required ? $none + $hours : $hours;
}