Fix time code sorting.

Event lists show 00:XX codes after 23:XX codes.
This commit is contained in:
2019-10-19 00:50:38 +02:00
parent f7eebd54f5
commit 64a85e92f5
2 changed files with 16 additions and 3 deletions

View File

@@ -37,6 +37,19 @@ def timedelta_to_str(data: timedelta) -> str:
)
def by_time(e):
"""
Custom sort key for sorting by time codes in the format HH:MM
This version sorts codes with hour '00' after '23'
"""
if not hasattr(e, "time") or isinstance(e.time, time):
return id(e)
if e.time.hour == 0:
return f"24{e.time.minute}"
return f"{e.time.hour}{e.time.minute}"
def compute_timedelta(start: time, end: time) -> float:
if not start or not end:
return 0