You are here

function lingotek_human_readable_timestamp in Lingotek Translation 7.5

Same name and namespace in other branches
  1. 7.7 lingotek.util.inc \lingotek_human_readable_timestamp()
  2. 7.4 lingotek.util.inc \lingotek_human_readable_timestamp()
  3. 7.6 lingotek.util.inc \lingotek_human_readable_timestamp()
3 calls to lingotek_human_readable_timestamp()
lingotek_bulk_grid_form in ./lingotek.bulk_grid.inc
lingotek_grid_get_rows in ./lingotek.bulk_grid.inc
Dynamic query processing function for the grid Since the header defines which columns are shown, this query gets all possible values and refines the header using the columns selected in the UI The filters are also processed here
lingotek_push_form in ./lingotek.page.inc
Upload Content Form. (Upload to Lingotek)

File

./lingotek.util.inc, line 936
Utility functions.

Code

function lingotek_human_readable_timestamp($unix_timestamp, $as_array = FALSE) {
  $time = time() - $unix_timestamp;
  $intervals = array(
    31536000 => t('year'),
    2592000 => t('month'),
    604800 => t('week'),
    86400 => t('day'),
    3600 => t('hour'),
    60 => t('minute'),
    1 => t('second'),
  );
  foreach ($intervals as $unit => $text) {
    if ($time < $unit) {
      continue;
    }
    $number = floor($time / $unit);
    if ($as_array) {
      return array(
        'number' => $number,
        'interval' => $text . ($number > 1 ? 's' : ''),
      );
    }
    else {
      return $number . ' ' . $text . ($number > 1 ? 's' : '');
    }
  }
  if ($as_array) {
    return array(
      'number' => 0,
      'interval' => t('seconds'),
    );
  }
  else {
    return '0 ' . t('seconds');
  }
}