<?php
/*******************************************************************************
* IKBIN
* Copyright (C) 2007 ikbin project administrators
*
*************************************************************************************/
class utilityfunctions{
function fuzzyDate($timestamp){
if($timestamp==0){return 'none';}
$timestamp = strtotime($timestamp);
if($timestamp > time())
//we don't handle future dates
return date('Y-m-d H:i', $timestamp);
elseif($timestamp > mktime(0,0,0))
//since midnight so it's today
return 'Today '.date('H:i', $timestamp);
elseif($timestamp > mktime(0,0,0) - 86400)
//since midnight 1 day ago so it's yesterday
return 'Yesterday '.date('H:i', $timestamp);
elseif($timestamp > mktime(0,0,0) - 86400*7)
//since midnight 7 days ago so it's this week
return date('l H:i', $timestamp);
elseif($timestamp > mktime(0,0,0,1,1))
//since 1st Jan so it's this year
return date('F j', $timestamp);
else
//ages ago!
return date('F Y', $timestamp);
}
function fuzzyage($timestamp){
if($timestamp==0){return 'none';}
$timestamp=strtotime($timestamp);
//is it D, M, HR?
//return round((time()-$timestamp)/86400).' d';
if($timestamp > time())
//we don't handle future dates
//return 'error:change offset!';
return '0 m';
elseif($timestamp > (time()-3600))//mktime(0,0,0))
//59 or less minutes old
return round((time()-$timestamp)/60).' m';
elseif($timestamp > (time()-86400))//mktime(0,0,0) - 86400)
//23 or fewer hours old
return round((time()-$timestamp)/3600).' h';
else
//everything else in days
return round((time()-$timestamp)/86400).' d';
}
function fuzzysize($size){
switch(true){
//bits
//bytes
case ($size<1000):
return $size.' B';
break;
//kbytes
case ($size<1000000):
return round($size/1024,2).' KB';
break;
//mbytes
case ($size<1000000000):
return round($size/1048576,2).' MB';
break;
//gbytes
//tbytes
default:
return round($size/1073741824,2).' GB';
break;
}
}
}//class
?>