function date_format_interval in Date 6.2
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 date_api.module \date_format_interval()
- 7.3 date_api/date_api.module \date_format_interval()
- 7 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/
date.module - Helper function for creating formatted date arrays from a formatter.
- theme_date_time_ago in theme/
theme.inc
File
- ./
date_api.module, line 801 - 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 = time() - date_format($date, 'U');
if ($interval > 0) {
return t('!time ago', array(
'!time' => format_interval($interval, $granularity),
));
}
else {
return format_interval(abs($interval), $granularity);
}
}