function DateHelper::minutes

Same name in other branches
  1. 9 core/lib/Drupal/Core/Datetime/DateHelper.php \Drupal\Core\Datetime\DateHelper::minutes()
  2. 10 core/lib/Drupal/Core/Datetime/DateHelper.php \Drupal\Core\Datetime\DateHelper::minutes()
  3. 11.x core/lib/Drupal/Core/Datetime/DateHelper.php \Drupal\Core\Datetime\DateHelper::minutes()

Constructs an array of minutes.

Parameters

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

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

int $increment: An integer value to increment the values. Defaults to 1.

Return value

array An array of minutes in the selected format.

File

core/lib/Drupal/Core/Datetime/DateHelper.php, line 383

Class

DateHelper
Defines Gregorian Calendar date values.

Namespace

Drupal\Core\Datetime

Code

public static function minutes($format = 'i', $required = FALSE, $increment = 1) {
    $minutes = [];
    // Ensure $increment has a value so we don't loop endlessly.
    if (empty($increment)) {
        $increment = 1;
    }
    for ($i = 0; $i < 60; $i += $increment) {
        $formatted = $format == 'i' ? DrupalDateTime::datePad($i) : $i;
        $minutes[$i] = $formatted;
    }
    $none = [
        '' => '',
    ];
    return !$required ? $none + $minutes : $minutes;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.