function date_increment_round

Rounds minutes and seconds to nearest requested value.

Parameters

$date:

$increment:

1 call to date_increment_round()
form_type_datelist_value in drupal/core/modules/datetime/datetime.module
Element value callback for datelist element.

File

drupal/core/modules/datetime/datetime.module, line 1045
Field hooks to implement a simple datetime field.

Code

function date_increment_round(&$date, $increment) {

  // Round minutes and seconds, if necessary.
  if ($date instanceof DrupalDateTime && $increment > 1) {
    $day = intval(date_format($date, 'j'));
    $hour = intval(date_format($date, 'H'));
    $second = intval(round(intval(date_format($date, 's')) / $increment) * $increment);
    $minute = intval(date_format($date, 'i'));
    if ($second == 60) {
      $minute += 1;
      $second = 0;
    }
    $minute = intval(round($minute / $increment) * $increment);
    if ($minute == 60) {
      $hour += 1;
      $minute = 0;
    }
    date_time_set($date, $hour, $minute, $second);
    if ($hour == 24) {
      $day += 1;
      $hour = 0;
      $year = date_format($date, 'Y');
      $month = date_format($date, 'n');
      date_date_set($date, $year, $month, $day);
    }
  }
  return $date;
}