You are here

function date_format_interval in Date 6

Same name and namespace in other branches
  1. 8 date_api/date_api.module \date_format_interval()
  2. 5.2 date_api.module \date_format_interval()
  3. 6.2 date_api.module \date_format_interval()
  4. 7.3 date_api/date_api.module \date_format_interval()
  5. 7 date_api/date_api.module \date_format_interval()
  6. 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

1 call to date_format_interval()
date_formatter_process in date/date.module
Helper function for creating formatted date arrays from a formatter.

File

./date_api.module, line 477
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) {
  $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);
  }
}