make duration formatting more forgiving
This commit is contained in:
parent
3af4647804
commit
80963966b2
|
@ -48,12 +48,14 @@ def parse_size(s: typing.Optional[str]) -> typing.Optional[int]:
|
|||
raise ValueError("Invalid size specification.")
|
||||
|
||||
|
||||
def pretty_duration(secs):
|
||||
def pretty_duration(secs: typing.Optional[float]) -> str:
|
||||
formatters = [
|
||||
(100, "{:.0f}s"),
|
||||
(10, "{:2.1f}s"),
|
||||
(1, "{:1.2f}s"),
|
||||
]
|
||||
if secs is None:
|
||||
return ""
|
||||
|
||||
for limit, formatter in formatters:
|
||||
if secs >= limit:
|
||||
|
|
|
@ -47,6 +47,7 @@ def test_pretty_duration():
|
|||
assert human.pretty_duration(10000) == "10000s"
|
||||
assert human.pretty_duration(1.123) == "1.12s"
|
||||
assert human.pretty_duration(0.123) == "123ms"
|
||||
assert human.pretty_duration(None) == ""
|
||||
|
||||
|
||||
def test_format_address():
|
||||
|
|
Loading…
Reference in New Issue