NDOJ/judge/jinja2/timedelta.py

31 lines
689 B
Python
Raw Normal View History

2020-01-21 06:35:58 +00:00
import datetime
from judge.utils.timedelta import nice_repr
from . import registry
@registry.filter
2022-05-14 17:57:27 +00:00
def timedelta(value, display="long"):
2020-01-21 06:35:58 +00:00
if value is None:
return value
return nice_repr(value, display)
@registry.filter
2022-05-14 17:57:27 +00:00
def timestampdelta(value, display="long"):
2020-01-21 06:35:58 +00:00
value = datetime.timedelta(seconds=value)
return timedelta(value, display)
@registry.filter
def seconds(timedelta):
return timedelta.total_seconds()
@registry.filter
2022-05-14 17:57:27 +00:00
@registry.render_with("time-remaining-fragment.html")
2021-12-10 22:36:55 +00:00
def as_countdown(time):
time_now = datetime.datetime.now(datetime.timezone.utc)
initial = abs(time - time_now)
2022-05-14 17:57:27 +00:00
return {"countdown": time, "initial": initial}