1
0
Fork 0
feedizer-php/htdocs/includes/helpers.inc.php
2015-11-13 23:51:46 +01:00

41 lines
1.1 KiB
PHP

<?php
function sec2hms($seconds) {
if ($seconds == 0)
return '0 seconds';
$hours = floor($seconds / 3600);
$seconds = $seconds % 3600;
if ($hours > 0)
$hstr = $hours . ($hours > 1 ? ' hours' : ' hour');
else
$hstr = false;
if ($seconds > 0) {
$minutes = floor($seconds / 60);
$seconds = $seconds % 60;
if ($minutes > 0)
$mstr .= $minutes . ($minutes > 1 ? ' minutes' : ' minute');
else
$mstr = false;
if ($seconds > 0)
$sstr .= $seconds . ($seconds > 1 ? ' seconds' : ' second');
else
$sstr = false;
} else {
$mstr = false;
$sstr = false;
}
if ($hstr and $mstr and $sstr)
return $hstr . ', ' . $mstr . ' and ' . $sstr;
elseif ($hstr and $mstr)
return $hstr . ' and ' . $mstr;
elseif ($hstr and $sstr)
return $hstr . ' and ' . $sstr;
elseif ($mstr and $sstr)
return $mstr . ' and ' . $sstr;
else
return $hstr . $mstr . $sstr;
}