Robson » Code » PHP » Fuzzy Clock Short

 
<?
 
// fuzzy clock short v1.0
 
// this is my attempt at creating a fuzzy clock with the smallest number of characters.
// function and call are just for convienience, the actual code is between the comments
 
function ic_fuzzy_clock($s=0)
{
if(!$s)$s=time();
 
// start
$h=date(G,$s);
$m=round(date(i,$s)/5);
$i=explode('|','one|two|three|four|five|six|seven|eight|nine|ten|eleven');
$f[]='midnight';
$x=array_merge($f,$i,array('noon'),$i,$f);
$b=explode('|',$x[$h].'|five|ten|quarter|twenty|twenty five|half|twenty five|twenty|quarter|ten|five|'.$x[$h+1]);
$t=$b[$m];
return !$m||$m==12?$t:($m>6?$t.' to '.$x[$h+1]:$t.' past '.$x[$h]);
// end
 
}
echo ic_fuzzy_clock();
 
?>
 
© 2004-17 robson | cc unless stated