function date_format_interval in Date 7
Same name and namespace in other branches
- 8 date_api/date_api.module \date_format_interval()
- 5.2 date_api.module \date_format_interval()
- 6.2 date_api.module \date_format_interval()
- 6 date_api.module \date_format_interval()
- 7.3 date_api/date_api.module \date_format_interval()
- 7.2 date_api/date_api.module \date_format_interval()
An override for interval formatting that adds past and future context
Parameters
DateTime $date:
integer $granularity:
Return value
formatted string
2 calls to date_format_interval()
- date_formatter_process in ./
date.module - Helper function for creating formatted date arrays from a formatter.
- theme_date_time_ago in date_api/
theme/ theme.inc
File
- date_api/
date_api.module, line 1259 - 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_format_interval($date, $granularity = 2) {
// If no date is sent, then return nothing
if (empty($date)) {
return NULL;
}
$interval = REQUEST_TIME - $date
->format('U');
if ($interval > 0) {
return t('!time ago', array(
'!time' => format_interval($interval, $granularity),
));
}
else {
return format_interval(abs($interval), $granularity);
}
}