2004-02-02 23:34:39 +00:00
|
|
|
<?php
|
2008-08-05 22:43:14 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2008 University of California
|
|
|
|
//
|
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2004-02-02 23:34:39 +00:00
|
|
|
|
|
|
|
// 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){
|
2010-11-04 18:20:57 +00:00
|
|
|
$pre="In ";
|
|
|
|
$post="";
|
|
|
|
$diff=-$diff;
|
2005-03-24 11:42:04 +00:00
|
|
|
} else {
|
2010-11-04 18:20:57 +00:00
|
|
|
$pre="";
|
|
|
|
$post=" ago";
|
2005-03-24 11:42:04 +00:00
|
|
|
}
|
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;
|
2010-11-04 18:20:57 +00:00
|
|
|
}
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
?>
|