2004-02-02 23:34:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// express a time difference in readable form
|
|
|
|
//
|
|
|
|
function time_diff_str($t1, $t2) {
|
|
|
|
if (!$t1 || !$t2) return "---";
|
|
|
|
$diff = $t2 - $t1;
|
2005-03-24 11:42:04 +00:00
|
|
|
if ($diff<0){
|
|
|
|
$pre="In ";
|
|
|
|
$post="";
|
|
|
|
$diff=-$diff;
|
|
|
|
} else {
|
|
|
|
$pre="";
|
|
|
|
$post=" ago";
|
|
|
|
}
|
2004-02-02 23:34:39 +00:00
|
|
|
$x = "";
|
2005-03-24 11:42:04 +00:00
|
|
|
|
|
|
|
|
2004-02-02 23:34:39 +00:00
|
|
|
if ($diff >= 3600*24) {
|
|
|
|
$n = (int) ($diff/(3600*24));
|
|
|
|
if ($n == 1) {
|
|
|
|
$x .= "1 day ";
|
|
|
|
} else {
|
|
|
|
$x .= "$n days ";
|
|
|
|
}
|
2005-03-24 11:42:04 +00:00
|
|
|
return $pre.$x.$post;
|
2004-02-02 23:34:39 +00:00
|
|
|
//$diff -= $n*3600*24;
|
2005-03-24 11:42:04 +00:00
|
|
|
} elseif ($diff >= 3600) {
|
2004-02-02 23:34:39 +00:00
|
|
|
$n = (int) ($diff/3600);
|
|
|
|
if ($n == 1) {
|
|
|
|
$x .= "1 hour ";
|
|
|
|
} else {
|
|
|
|
$x .= $n." hours ";
|
|
|
|
}
|
2005-03-24 11:42:04 +00:00
|
|
|
return $pre.$x.$post;
|
2004-02-02 23:34:39 +00:00
|
|
|
//$diff -= $n*3600;
|
2005-03-24 11:42:04 +00:00
|
|
|
} elseif ($diff >= 60) {
|
2004-02-02 23:34:39 +00:00
|
|
|
$n = (int) ($diff/60);
|
|
|
|
if ($n == 1) {
|
|
|
|
$x .= "1 minute ";
|
|
|
|
} else {
|
|
|
|
$x .= $n." minutes ";
|
|
|
|
}
|
2005-03-24 11:42:04 +00:00
|
|
|
return $pre.$x.$post;
|
|
|
|
} elseif($diff > 1 || $diff==0) {
|
|
|
|
return $pre."$diff seconds".$post;
|
|
|
|
} elseif($diff == 1){
|
|
|
|
return $pre."$diff seconds".$post;
|
|
|
|
}
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
?>
|