function format_interval

cis7 common.inc format_interval($interval, $granularity = 2, $langcode = NULL)
cle7 common.inc format_interval($interval, $granularity = 2, $langcode = NULL)
elmsmedia7 common.inc format_interval($interval, $granularity = 2, $langcode = NULL)
icor7 common.inc format_interval($interval, $granularity = 2, $langcode = NULL)
meedjum_blog7 common.inc format_interval($interval, $granularity = 2, $langcode = NULL)
mooc7 common.inc format_interval($interval, $granularity = 2, $langcode = NULL)

Formats a time interval with the requested granularity.

Parameters

$interval: The length of the interval in seconds.

$granularity: How many different units to display in the string.

$langcode: Optional language code to translate to a language other than what is used to display the page.

Return value

A translated string representation of the interval.

Related topics

44 calls to format_interval()
aggregator_view in modules/aggregator/aggregator.admin.inc
Displays the aggregator administration page.
apc_requirements in sites/all/modules/ulmus/apc/apc.install
Implements hook_requirements().
backup_migrate_drush_destination_files in sites/all/modules/ulmus/backup_migrate/includes/backup_migrate.drush.inc
Get a list of files in a given destination
backup_migrate_ui_destination_display_files in sites/all/modules/ulmus/backup_migrate/includes/destinations.inc
List the backup files in the given destination.
boost_exit in sites/all/modules/ulmus/boost/boost.module
Implements hook_exit().

... See full list

25 string references to 'format_interval'
aggregator_form_aggregator_admin_form_alter in modules/aggregator/aggregator.processor.inc
Implements hook_form_aggregator_admin_form_alter().
aggregator_form_feed in modules/aggregator/aggregator.admin.inc
Form constructor for adding and editing feed sources.
aggregator_form_opml in modules/aggregator/aggregator.admin.inc
Form constructor for importing feeds from OPML.
boost_admin_settings in sites/all/modules/ulmus/boost/boost.admin.inc
Form builder; Configure boost settings.
date_all_day_date_formatter_dates_alter in sites/all/modules/ulmus/date/date_all_day/date_all_day.module
Implements hook_date_formatter_dates_alter().

... See full list

File

includes/common.inc, line 1908
Common functions that many Drupal modules will need to reference.

Code

function format_interval($interval, $granularity = 2, $langcode = NULL) {
  $units = array(
    '1 year|@count years' => 31536000,
    '1 month|@count months' => 2592000,
    '1 week|@count weeks' => 604800,
    '1 day|@count days' => 86400,
    '1 hour|@count hours' => 3600,
    '1 min|@count min' => 60,
    '1 sec|@count sec' => 1,
  );
  $output = '';
  foreach ($units as $key => $value) {
    $key = explode('|', $key);
    if ($interval >= $value) {
      $output .= ($output ? ' ' : '') . format_plural(floor($interval / $value), $key[0], $key[1], array(), array('langcode' => $langcode));
      $interval %= $value;
      $granularity--;
    }

    if ($granularity == 0) {
      break;
    }
  }
  return $output ? $output : t('0 sec', array(), array('langcode' => $langcode));
}