1 date.inc | date_format_interval($date, $granularity = 2, $display_ago = TRUE) |
Formats a time interval with granularity, including past and future context.
Parameters
object $date: The current date object.
int $granularity: (optional) Number of units to display in the string. Defaults to 2.
Return value
string: A translated string representation of the interval.
See also
File
- core/
includes/ date.inc, line 723 - Date API functions.
Code
function date_format_interval($date, $granularity = 2, $display_ago = TRUE) {
// If no date is sent, then return nothing.
if (empty($date)) {
return NULL;
}
$interval = REQUEST_TIME - $date->format('U');
if ($interval > 0) {
return $display_ago ? t('!time ago', array('!time' => format_interval($interval, $granularity))) :
t('!time', array('!time' => format_interval($interval, $granularity)));
}
else {
return format_interval(abs($interval), $granularity);
}
}