You are here

function date_increment_round in Date 7.3

Same name and namespace in other branches
  1. 8 date_api/date_api.module \date_increment_round()
  2. 5.2 date_api_elements.inc \date_increment_round()
  3. 6.2 date_api.module \date_increment_round()
  4. 6 date_api_elements.inc \date_increment_round()
  5. 7 date_api/date_api_elements.inc \date_increment_round()
  6. 7.2 date_api/date_api.module \date_increment_round()

Helper function to round minutes and seconds to requested value.

6 calls to date_increment_round()
date_default_date in date_api/date_api_elements.inc
Create a date object from a datetime string value.
date_devel_generate in ./date.devel_generate.inc
Implements hook_devel_generate().
date_popup_input_date in date_popup/date_popup.module
Helper function for extracting a date value out of user input.
date_popup_process_time_part in date_popup/date_popup.module
Process the time portion of the element.
date_select_input_date in date_api/date_api_elements.inc
Helper function for creating a date object out of user input.

... See full list

File

date_api/date_api.module, line 3003
This module will make the date API available to other modules.

Code

function date_increment_round(&$date, $increment) {

  // Round minutes and seconds, if necessary.
  if (is_object($date) && $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;
}