function date_increment_round in Date 5.2
Same name and namespace in other branches
- 8 date_api/date_api.module \date_increment_round()
- 6.2 date_api.module \date_increment_round()
- 6 date_api_elements.inc \date_increment_round()
- 7.3 date_api/date_api.module \date_increment_round()
- 7 date_api/date_api_elements.inc \date_increment_round()
- 7.2 date_api/date_api.module \date_increment_round()
Helper function to round minutes and seconds to requested value.
3 calls to date_increment_round()
- date_generate in date/
date_content_generate.inc - date_popup_process in date_popup/
date_popup.module - Javascript popup element processing. Add popup attributes to $element.
- date_select_process in ./
date_api_elements.inc - Flexible date/time drop-down selector.
File
- ./
date_api_elements.inc, line 371 - 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;
}