verbose/lib/ght.php
2023-11-20 12:42:57 +01:00

50 baris
1,1 KiB
PHP

<?php
function ght($ts,$fa=null,$sd=2) {
/*
$ts is seconds (can be float)
if not null, $fa has to be an array defining the output suffixes, see below
its default ;-)
$sd is how many decimals to put after a dot after seconds (can be 0)
*/
if ($fa==null)
$fa=[' year, ',' years, ',' week, ',' weeks, ',' day, ',' days, ',' hour, ',' hours, ',' minute, ',' minutes, ',' second',' seconds'];
$out='';
$i=0;
// years
$x=floor($ts/31536000);
if ($x>0)
($x==1) ? $out.=$x.$fa[$i] : $out.=$x.$fa[$i+1];
$ts=$ts-$x*31536000;
$i+=2;
// weeks
$x=floor($ts/604800);
if ($x>0)
($x==1) ? $out.=$x.$fa[$i] : $out.=$x.$fa[$i+1];
$ts=$ts-$x*604800;
$i+=2;
// days
$x=floor($ts/86400);
if ($x>0)
($x==1) ? $out.=$x.$fa[$i] : $out.=$x.$fa[$i+1];
$ts=$ts-$x*86400;
$i+=2;
// hours
$x=floor($ts/3600);
if ($x>0)
($x==1) ? $out.=$x.$fa[$i] : $out.=$x.$fa[$i+1];
$ts=$ts-$x*3600;
$i+=2;
// minutes
$x=floor($ts/60);
if ($x>0)
($x==1) ? $out.=$x.$fa[$i] : $out.=$x.$fa[$i+1];
$ts=$ts-$x*60;
$i+=2;
// seconds
$x=round($ts,$sd);
($x==1) ? $out.=$x.$fa[$i] : $out.=$x.$fa[$i+1];
return $out;
}
?>