From c57e365ef97272cc08601374e4de2f5bcd614335 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 7 Oct 2009 14:22:32 +0200 Subject: Added datetime to fuzzy age function Ignore-this: 6d0e4f4fce5911667467f92cefaabaef This still needs to be made accessible within the dtformat config option. darcs-hash:20091007122232-6e07b-bbb6f97ae84bc9aa079fe328665f8164ae119804.gz --- inc/common.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index 069314273..82d5f69ee 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1192,6 +1192,37 @@ function filesize_h($size, $dec = 1){ return round($size, $dec) . ' ' . $sizes[$i]; } +/** + * Return the given timestamp as human readable, fuzzy age + * + * @author Andreas Gohr + */ +function datetime_h($dt){ + global $lang; + + $ago = time() - $dt; + if($ago > 24*60*60*30*12*2){ + return sprintf($lang['years'], round($ago/(24*60*60*30*12))); + } + if($ago > 24*60*60*30*2){ + return sprintf($lang['months'], round($ago/(24*60*60*30))); + } + if($ago > 24*60*60*7*2){ + return sprintf($lang['weeks'], round($ago/(24*60*60*7))); + } + if($ago > 24*60*60*2){ + return sprintf($lang['days'], round($ago/(24*60*60))); + } + if($ago > 60*60*2){ + return sprintf($lang['hours'], round($ago/(60*60))); + } + if($ago > 60*2){ + return sprintf($lang['minutes'], round($ago/(60))); + } + return sprintf($lang['seconds'], $ago); + +} + /** * return an obfuscated email address in line with $conf['mailguard'] setting * -- cgit v1.2.3