Module: check_mk
Branch: master
Commit: 5c37fb0b8b991189b24737650a4936b8a06479b2
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5c37fb0b8b9911…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Mar 25 18:03:07 2015 +0100
New functions for date in human readable form
---
web/htdocs/lib.py | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/web/htdocs/lib.py b/web/htdocs/lib.py
index 9e6616a..caedd88 100644
--- a/web/htdocs/lib.py
+++ b/web/htdocs/lib.py
@@ -620,6 +620,37 @@ def age_human_readable(secs, min_only=False):
return "%.0f %s" % (years, _("years"))
+def date_human_readable(timestamp):
+ # This can be localized:
+ return time.strftime(_("%m/%d/%Y"), time.localtime(timestamp))
+
+def date_range_human_readable(start_time, end_time):
+ start_time_local = time.localtime(start_time)
+ end_time_local = time.localtime(end_time)
+ if start_time_local[:3] == end_time_local[:3]: # same day
+ return date_human_readable(start_time)
+
+ elif start_time_local[:2] == end_time_local[:2]: # same month
+ date_format = _("%m/%d1-%d2/%Y")
+ f = date_format.replace("%d2", time.strftime("%d",
end_time_local))
+ f = f.replace("%d1", "%d")
+ return time.strftime(f, start_time_local)
+
+ elif start_time_local[0] == end_time_local[0]: # same year
+ date_format = _("%m1/%d1/%Y - %m2/%d2/%Y")
+ f = date_format.replace("%d2", time.strftime("%d",
end_time_local))
+ f = f.replace("%m2", time.strftime("%m", end_time_local))
+ f = f.replace("%d1", "%d").replace("%m1",
"%m")
+ return time.strftime(f, start_time_local)
+
+ else:
+ return date_human_readable(start_time) + " - " + \
+ date_human_readable(end_time)
+
+# Just print year and month, no day
+def date_month_human_readable(timestamp):
+ # TODO: %B will currently not be localized
+ return time.strftime(_("%B %Y"), time.localtime(timestamp))
def bytes_human_readable(b, base=1024.0, bytefrac=True, unit="B"):