<?php
function duration($start,$end=null) {
$end = is_null($end) ? time() : $end;
$result = $end - $start;
return secs_to_h($result);
}
function secs_to_h($secs) {
$units = array(
" decade " => 314496000,
" year " => 31449600,
" month " => 2419200,
" week " => 604800,
" day " => 86400,
" hour " => 3600,
" minute " => 60,
" second " => 1
);
if ($secs == 0) { return "0 seconds"; }
$is = "";
foreach ($units as $name => $divisor) {
if ($quot = intval($secs / $divisor)) {
$is .= "$quot"."$name";
$secs -= $quot * $divisor;
}
}
$ex = explode(" ", $is);
$fed = $ex[0];
$c = $ex[1];
if ($fed !== "1") { $c = $c."s"; }
return $fed." ".$c;
}
echo secs_to_h(3600);
?>