Browse Source

Konzistentní krátké datum.

okenkove_obalky
parent
commit
5881a9d506
  1. 13
      seminar/templatetags/utils.py

13
seminar/templatetags/utils.py

@ -1,4 +1,5 @@
from django import template
from django.utils.safestring import mark_safe
from datetime import datetime, timedelta
from pytz import timezone
from mamweb.settings import TIME_ZONE
@ -15,13 +16,5 @@ def kratke_datum(dt):
if not isinstance(dt, datetime):
logger.warning(f"Špatné volání filtru {__name__}: {dt}")
return False
naive_now = datetime.now()
tz = timezone(TIME_ZONE)
now = tz.localize(naive_now)
delta = now - dt
if delta <= timedelta(days=1):
return dt.strftime("%H:%M")
if delta <= timedelta(days=365): # Timedelta neumí vyjádřit 1 rok
return dt.strftime("%d. %m.")
return dt.strftime("%d. %m. %Y")
out = f'<span title="{dt.strftime("%d. %m. %Y %H:%M")}">{dt.day}.{dt.month}.<span style="text-decoration:overline">{dt.year%100}</span>'
return mark_safe(out)

Loading…
Cancel
Save