NDOJ/judge/jinja2/datetime.py

28 lines
792 B
Python
Raw Normal View History

2020-01-21 06:35:58 +00:00
import functools
from django.template.defaultfilters import date, time
from django.templatetags.tz import localtime
from django.utils.translation import gettext as _
from . import registry
def localtime_wrapper(func):
@functools.wraps(func)
def wrapper(datetime, *args, **kwargs):
2022-05-14 17:57:27 +00:00
if getattr(datetime, "convert_to_local_time", True):
2020-01-21 06:35:58 +00:00
datetime = localtime(datetime)
return func(datetime, *args, **kwargs)
return wrapper
registry.filter(localtime_wrapper(date))
registry.filter(localtime_wrapper(time))
@registry.function
2022-05-14 17:57:27 +00:00
@registry.render_with("widgets/relative-time.html")
def relative_time(time, format=_("N j, Y, g:i a"), rel=_("{time}"), abs=_("on {time}")):
return {"time": time, "format": format, "rel_format": rel, "abs_format": abs}