function format_interval

Same name and namespace in other branches
  1. 7.x drupal-7.x/includes/common.inc \format_interval()

Format a time interval with the requested granularity.

Parameters

$timestamp: 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

15 calls to format_interval()
aggregator_view in drupal-6.x/modules/aggregator/aggregator.admin.inc
Displays the aggregator administration page.
hook_requirements in documentation-6.x/developer/hooks/install.php
Check installation requirements and do status reporting.
statistics_top_pages in drupal-6.x/modules/statistics/statistics.admin.inc
Menu callback; presents the "top pages" page.
statistics_top_referrers in drupal-6.x/modules/statistics/statistics.admin.inc
Menu callback; presents the "referrer" page.
statistics_top_visitors in drupal-6.x/modules/statistics/statistics.admin.inc
Menu callback; presents the "top visitors" page.

... See full list

5 string references to 'format_interval'
aggregator_admin_settings in drupal-6.x/modules/aggregator/aggregator.admin.inc
Form builder; Configure the aggregator system.
aggregator_form_feed in drupal-6.x/modules/aggregator/aggregator.admin.inc
Form builder; Generate a form to add/edit feed sources.
statistics_access_logging_settings in drupal-6.x/modules/statistics/statistics.admin.inc
Form builder; Configure access logging.
system_performance_settings in drupal-6.x/modules/system/system.admin.inc
Form builder; Configure site performance settings.
user_block in drupal-6.x/modules/user/user.module
Implementation of hook_block().

Archivo

drupal-6.x/includes/common.inc, line 1311
Common functions that many Drupal modules will need to reference.

Código

function format_interval($timestamp, $granularity = 2, $langcode = NULL) {
  $units = array(
    '1 year|@count years' => 31536000,
    '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 ($timestamp >= $value) {
      $output .= ($output ? ' ' : '') . format_plural(floor($timestamp / $value), $key[0], $key[1], array(), $langcode);
      $timestamp %= $value;
      $granularity--;
    }

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