ui: show 1d and 1h rather than 1.0d and 1.0h

This commit is contained in:
rr-
2018-11-13 16:06:50 +01:00
parent a823c9041e
commit b9a0934e74
+9 -2
View File
@@ -4,6 +4,13 @@ import typing as T
import urwid
def format_float(num: float) -> str:
ret = f"{num:.01f}"
if ret.endswith("0"):
ret = ret[:-2]
return ret
def format_timespan(timespan: datetime.timedelta) -> str:
num = timespan.total_seconds()
if num < 60.0:
@@ -13,9 +20,9 @@ def format_timespan(timespan: datetime.timedelta) -> str:
return f"~{int(num)}m"
num /= 60
if num < 24.0:
return f"~{num:.01f}h"
return f"~{format_float(num)}h"
num /= 24
return f"~{num:.01f}d"
return f"~{format_float(num)}d"
class CustomProgressBar(urwid.Widget):