public static function DateHelper::seconds

public static DateHelper::seconds($format = 's', $required = FALSE, $increment = 1)

Constructs an array of seconds.

Parameters

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

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 seconds in the selected format.

File

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

Class

DateHelper
Defines Gregorian Calendar date values.

Namespace

Drupal\Core\Datetime

Code

public static function seconds($format = 's', $required = FALSE, $increment = 1) {
  $seconds = array();
  // 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 == 's' ? DrupalDateTime::datePad($i) : $i;
    $seconds[$i] = $formatted;
  }
  $none = array('' => '');
  return !$required ? $none + $seconds : $seconds;
}

© 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::seconds/8.1.x