Browse Source

Corrected reldate formatters

Ralfp 12 years ago
parent
commit
e0e94a9b08
1 changed files with 14 additions and 4 deletions
  1. 14 4
      misago/template/templatetags/django2jinja.py

+ 14 - 4
misago/template/templatetags/django2jinja.py

@@ -59,16 +59,22 @@ def date(val, arg=""):
 
 
 def reldate(val, arg=""):
 def reldate(val, arg=""):
     now = datetime.now(utc if is_aware(val) else None)
     now = datetime.now(utc if is_aware(val) else None)
+    local_now = localtime(now)
     diff = now - val
     diff = now - val
     local = localtime(val)
     local = localtime(val)
 
 
-    # Common situations
-    if diff.days == 0:
+    # Today check
+    if format(local, 'Y-z') == format(local_now, 'Y-z'):
         return _("Today, %(hour)s") % {'hour': time_format(local, formats['TIME_FORMAT'])}
         return _("Today, %(hour)s") % {'hour': time_format(local, formats['TIME_FORMAT'])}
-    if diff.days == 1:
+    # Yesteday check
+    yesterday = localtime(now - timedelta(days=1))
+    if format(local, 'Y-z') == format(yesterday, 'Y-z'):
         return _("Yesterday, %(hour)s") % {'hour': time_format(local, formats['TIME_FORMAT'])}
         return _("Yesterday, %(hour)s") % {'hour': time_format(local, formats['TIME_FORMAT'])}
-    if diff.days == -1:
+    # Tomorrow Check
+    tomorrow = localtime(now + timedelta(days=1))
+    if format(local, 'Y-z') == format(tomorrow, 'Y-z'):
         return _("Tomorrow, %(hour)s") % {'hour': time_format(local, formats['TIME_FORMAT'])}
         return _("Tomorrow, %(hour)s") % {'hour': time_format(local, formats['TIME_FORMAT'])}
+    # Week check
     if diff.days > -7 or diff.days < 7:
     if diff.days > -7 or diff.days < 7:
         return _("%(day)s, %(hour)s") % {'day': format(local, 'l'), 'hour': time_format(local, formats['TIME_FORMAT'])}
         return _("%(day)s, %(hour)s") % {'day': format(local, 'l'), 'hour': time_format(local, formats['TIME_FORMAT'])}
 
 
@@ -81,6 +87,10 @@ def reltimesince(val, arg=""):
     diff = now - val
     diff = now - val
     local = localtime(val)
     local = localtime(val)
 
 
+    # Difference is greater than day for sure
+    if diff.days != 0:
+        return reldate(val, arg)
+
     # Display specific time
     # Display specific time
     if diff.seconds >= 0:
     if diff.seconds >= 0:
         if diff.seconds <= 60:
         if diff.seconds <= 60: