You are here

function lingotek_human_readable_timestamp in Lingotek Translation 7.4

Same name and namespace in other branches
  1. 7.7 lingotek.util.inc \lingotek_human_readable_timestamp()
  2. 7.5 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
@file Bulk Grid form
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 957
Utility functions.

Code

function lingotek_human_readable_timestamp($unix_timestamp, $as_array = FALSE) {
  $time = time() - $unix_timestamp;
  $intervals = array(
    31536000 => 'year',
    2592000 => 'month',
    604800 => 'week',
    86400 => 'day',
    3600 => 'hour',
    60 => 'minute',
    1 => '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' => 'seconds',
    );
  }
  else {
    return '0 seconds';
  }
}