function date_increment_round in Date 6.2
Same name and namespace in other branches
- 8 date_api/date_api.module \date_increment_round()
- 5.2 date_api_elements.inc \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_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.
- _date_content_generate in date/
date_content_generate.inc - Implementation of Devel module's hook_content_generate().
File
- ./
date_api.module, line 2741 - This module will make the date API available to other modules. Designed to provide a light but flexible assortment of functions and constants, with more functionality in additional files that are not loaded unless other modules specifically include them.
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;
}