diff options
Diffstat (limited to 'inc')
-rw-r--r-- | inc/common.php | 31 | ||||
-rw-r--r-- | inc/lang/en/lang.php | 7 |
2 files changed, 38 insertions, 0 deletions
diff --git a/inc/common.php b/inc/common.php index 069314273..82d5f69ee 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1193,6 +1193,37 @@ function filesize_h($size, $dec = 1){ } /** + * Return the given timestamp as human readable, fuzzy age + * + * @author Andreas Gohr <gohr@cosmocode.de> + */ +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 * * @author Harry Fuecks <hfuecks@gmail.com> diff --git a/inc/lang/en/lang.php b/inc/lang/en/lang.php index b43aa0e54..fbde8cab0 100644 --- a/inc/lang/en/lang.php +++ b/inc/lang/en/lang.php @@ -269,4 +269,11 @@ $lang['mu_lasterr'] = 'Last error:'; $lang['recent_global'] = 'You\'re currently watching the changes inside the <b>%s</b> namespace. You can also <a href="%s">view the recent changes of the whole wiki</a>.'; +$lang['years'] = '%d years'; +$lang['months'] = '%d months'; +$lang['weeks'] = '%d weeks'; +$lang['days'] = '%d days'; +$lang['hours'] = '%d hours'; +$lang['seconds'] = '%d seconds'; + //Setup VIM: ex: et ts=2 enc=utf-8 : |