W3cubDocs

/Drupal 8

protected static function 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;
}

© 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!Element!Datelist.php/function/Datelist::incrementRound/8.1.x