You are here

function date_increment_round in Date 7

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.3 date_api/date_api.module \date_increment_round()
  6. 7.2 date_api/date_api.module \date_increment_round()

Helper function to round minutes and seconds to requested value.

5 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
Implementation of Devel module's hook_content_generate().
date_popup_input_date in date_popup/date_popup.module
Helper function for extracting a date value out of user input.
date_select_input_date in date_api/date_api_elements.inc
Helper function for creating a date object out of user input.
date_text_input_date in date_api/date_api_elements.inc
Helper function for creating a date object out of user input.

File

date_api/date_api_elements.inc, line 93
Date API elements themes and validation. This file is only included during the edit process to reduce memory usage.

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;
}