the time diff function now supports times in the future as well. (ie. "In 2 days")

svn path=/trunk/boinc/; revision=5711
This commit is contained in:
Janus B. Kristensen 2005-03-24 11:42:04 +00:00
parent 51f388ee0c
commit b8cff6617c
1 changed files with 20 additions and 12 deletions

View File

@ -5,7 +5,17 @@
function time_diff_str($t1, $t2) {
if (!$t1 || !$t2) return "---";
$diff = $t2 - $t1;
if ($diff<0){
$pre="In ";
$post="";
$diff=-$diff;
} else {
$pre="";
$post=" ago";
}
$x = "";
if ($diff >= 3600*24) {
$n = (int) ($diff/(3600*24));
if ($n == 1) {
@ -13,31 +23,29 @@ function time_diff_str($t1, $t2) {
} else {
$x .= "$n days ";
}
return $x." ago";
return $pre.$x.$post;
//$diff -= $n*3600*24;
}
if ($diff >= 3600) {
} elseif ($diff >= 3600) {
$n = (int) ($diff/3600);
if ($n == 1) {
$x .= "1 hour ";
} else {
$x .= $n." hours ";
}
return $x." ago";
return $pre.$x.$post;
//$diff -= $n*3600;
}
if ($diff >= 60) {
} elseif ($diff >= 60) {
$n = (int) ($diff/60);
if ($n == 1) {
$x .= "1 minute ";
} else {
$x .= $n." minutes ";
}
return $x." ago";
}
if ($diff == 1) {
return "1 second ago";
}
return $diff." seconds ago";
return $pre.$x.$post;
} elseif($diff > 1 || $diff==0) {
return $pre."$diff seconds".$post;
} elseif($diff == 1){
return $pre."$diff seconds".$post;
}
}
?>