summaryrefslogtreecommitdiff
path: root/postgresqleu/util/time.py
diff options
context:
space:
mode:
authorMagnus Hagander2021-01-25 14:28:19 +0000
committerMagnus Hagander2021-01-25 14:33:06 +0000
commit8cbe450c0e3db453b4a99530b706c83e7dae7d2f (patch)
treed5a224f987084186f2f406b1e1ca3a90c4099d78 /postgresqleu/util/time.py
parentb4864bc1f4976939dd37578ff9a4fb17bce09f5e (diff)
Add utility functions to format times in the global tz
When going through templates the system takes care of it, but when manually rendering in the backend case needs to be taken, so add some utilities.
Diffstat (limited to 'postgresqleu/util/time.py')
-rw-r--r--postgresqleu/util/time.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/postgresqleu/util/time.py b/postgresqleu/util/time.py
index eab66cab..79ae8bef 100644
--- a/postgresqleu/util/time.py
+++ b/postgresqleu/util/time.py
@@ -1,4 +1,6 @@
from django.utils import timezone
+from django.utils.timesince import timeuntil, timesince
+from django.utils.formats import date_format
# Return a date represeting today in the timezone of the currently
@@ -12,3 +14,16 @@ def today_conference():
# (making it suitable for everything that is not conference-related).
def today_global():
return timezone.localdate(timezone.now(), timezone.get_default_timezone())
+
+
+# Return a string representing time until or time since, depending
+def time_sinceoruntil(t):
+ if t >= timezone.now():
+ return "in {}".format(timeuntil(t))
+ else:
+ return "{} ago".format(timesince(t))
+
+
+# Format a datetime long string
+def datetime_string(t):
+ return date_format(timezone.localtime(t), 'DATETIME_FORMAT', use_l10n=False)