app filter timedelta: Rebuild to UI friendly filter

master
Felix Stupp 3 years ago
parent c7df6b9fce
commit 0bbd7349a0
Signed by: zocker
GPG Key ID: 93E1BD26F6B02FB7

@ -150,9 +150,24 @@ def as_play_link(video_uri: str):
def tenary(b: bool, true_str: str, false_str: str) -> str: def tenary(b: bool, true_str: str, false_str: str) -> str:
return true_str if b else false_str return true_str if b else false_str
TIMEDELTA_FORMAT = (
datetime.timedelta(hours=1),
datetime.timedelta(minutes=1),
)
@flask_app.template_filter() @flask_app.template_filter()
def timedelta(seconds: int) -> str: def timedelta(seconds: int) -> str:
return repr(datetime.timedelta(seconds=seconds)) delta = datetime.timedelta(seconds=seconds)
ret = ""
for unit in TIMEDELTA_FORMAT:
if ret or unit <= delta:
unit_size = delta // unit
delta -= unit * unit_size
if ret:
ret += f"{unit_size:02}:"
else:
ret += f"{unit_size}:"
ret += f"{delta.seconds:02}"
return ret
#### ####

Loading…
Cancel
Save