Datelist::incrementRound

protected static Datelist::incrementRound(&$date, $increment)

Rounds minutes and seconds to nearest requested value.

Parameters

$date:

$increment:

File

core/lib/Drupal/Core/Datetime/Element/Datelist.php, line 365

Class

Datelist
Provides a datelist element.

Namespace

Drupal\Core\Datetime\Element

Code

protected static function incrementRound(&$date, $increment) {
  // Round minutes and seconds, if necessary.
  if ($date instanceof DrupalDateTime && $increment > 1) {
    $day = intval($date->format('j'));
    $hour = intval($date->format('H'));
    $second = intval(round(intval($date->format('s')) / $increment) * $increment);
    $minute = intval($date->format('i'));
    if ($second == 60) {
      $minute += 1;
      $second = 0;
    }
    $minute = intval(round($minute / $increment) * $increment);
    if ($minute == 60) {
      $hour += 1;
      $minute = 0;
    }
    $date->setTime($hour, $minute, $second);
    if ($hour == 24) {
      $day += 1;
      $year = $date->format('Y');
      $month = $date->format('n');
      $date->setDate($year, $month, $day);
    }
  }
  return $date;
}
doc_Drupal
2016-10-29 09:00:53
Comments
Leave a Comment

Please login to continue.