summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gohr <gohr@cosmocode.de>2009-10-07 14:22:32 +0200
committerAndreas Gohr <gohr@cosmocode.de>2009-10-07 14:22:32 +0200
commitc57e365ef97272cc08601374e4de2f5bcd614335 (patch)
tree8ed3504112d74466200927ae2519860789060075
parent47583ff0428eaa0d97e26f61f81ac6d199e9b446 (diff)
downloadrpg-c57e365ef97272cc08601374e4de2f5bcd614335.tar.gz
rpg-c57e365ef97272cc08601374e4de2f5bcd614335.tar.bz2
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
-rw-r--r--inc/common.php31
-rw-r--r--inc/lang/en/lang.php7
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 :