You are here

function duration in Production check & Production monitor 6

Same name in this branch
  1. 6 includes/prod_check.memcache.inc \duration()
  2. 6 includes/prod_check.apc.inc \duration()
Same name and namespace in other branches
  1. 7 includes/prod_check.memcache.inc \duration()
  2. 7 includes/prod_check.apc.inc \duration()

File

includes/prod_check.memcache.inc, line 256

Code

function duration($ts) {
  global $time;
  $years = (int) (($time - $ts) / (7 * 86400) / 52.177457);
  $rem = (int) ($time - $ts - $years * 52.177457 * 7 * 86400);
  $weeks = (int) ($rem / (7 * 86400));
  $days = (int) ($rem / 86400) - $weeks * 7;
  $hours = (int) ($rem / 3600) - $days * 24 - $weeks * 7 * 24;
  $mins = (int) ($rem / 60) - $hours * 60 - $days * 24 * 60 - $weeks * 7 * 24 * 60;
  $str = '';
  if ($years == 1) {
    $str .= "{$years} year, ";
  }
  if ($years > 1) {
    $str .= "{$years} years, ";
  }
  if ($weeks == 1) {
    $str .= "{$weeks} week, ";
  }
  if ($weeks > 1) {
    $str .= "{$weeks} weeks, ";
  }
  if ($days == 1) {
    $str .= "{$days} day,";
  }
  if ($days > 1) {
    $str .= "{$days} days,";
  }
  if ($hours == 1) {
    $str .= " {$hours} hour and";
  }
  if ($hours > 1) {
    $str .= " {$hours} hours and";
  }
  if ($mins == 1) {
    $str .= " 1 minute";
  }
  else {
    $str .= " {$mins} minutes";
  }
  return $str;
}