summaryrefslogtreecommitdiffstats
path: root/inc/util.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2017-12-01 23:01:11 +0100
committerSimon Rettberg2017-12-01 23:01:11 +0100
commitca593900b39779a8c84f6305ce19088ea3bc3854 (patch)
treeb38bc7c215b1a4de0f4cc642ea02c087922769ee /inc/util.inc.php
parentMerge branch 'master' into permission-manager (diff)
downloadslx-admin-ca593900b39779a8c84f6305ce19088ea3bc3854.tar.gz
slx-admin-ca593900b39779a8c84f6305ce19088ea3bc3854.tar.xz
slx-admin-ca593900b39779a8c84f6305ce19088ea3bc3854.zip
[inc/Util] Add helper to pretty-print timestamp
Diffstat (limited to 'inc/util.inc.php')
-rw-r--r--inc/util.inc.php24
1 files changed, 24 insertions, 0 deletions
diff --git a/inc/util.inc.php b/inc/util.inc.php
index 9bcfdf13..963b3416 100644
--- a/inc/util.inc.php
+++ b/inc/util.inc.php
@@ -462,4 +462,28 @@ SADFACE;
);
}
+ /**
+ * Transform timestamp to easily readable string.
+ * The format depends on how far the timestamp lies in the past.
+ * @param int $ts unix timestamp
+ * @return string human readable representation
+ */
+ public static function prettyTime($ts)
+ {
+ static $TODAY = false, $ETODAY = false, $YESTERDAY = false, $YEAR = false;
+ if (!$ETODAY) $ETODAY = strtotime('today 23:59:59');
+ if ($ts > $ETODAY) // TODO: Do we need strings for future too?
+ return date('d.m.Y H:i', $ts);
+ if (!$TODAY) $TODAY = strtotime('today 0:00');
+ if ($ts >= $TODAY)
+ return Dictionary::translate('lang_today') . ' ' . date('H:i', $ts);
+ if (!$YESTERDAY) $YESTERDAY = strtotime('yesterday 0:00');
+ if ($ts >= $YESTERDAY)
+ return Dictionary::translate('lang_yesterday') . ' ' . date('H:i', $ts);
+ if (!$YEAR) $YEAR = strtotime('this year 1/1');
+ if ($ts >= $YEAR)
+ return date('d.m. H:i', $ts);
+ return date('d.m.Y', $ts);
+ }
+
}