Skip to content
Snippets Groups Projects
Commit 8c79c0a5 authored by Martin Mareš's avatar Martin Mareš
Browse files

util_format: Funkce na formátování timedelta jako HH:MM:SS

parent 7f3b1b67
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,8 @@ from typing import Optional, Union
import mo
SECONDS_PER_DAY = 86400
def inflect_number(n: Union[int, decimal.Decimal], w1: str, w234: str, wother: str, unitprefix: str = '', wdecimal: Optional[str] = None) -> str:
return f"{format_decimal(n) if type(n) == decimal.Decimal else n} {inflect_by_number(n, w1, w234, wother, unitprefix=unitprefix, wdecimal=wdecimal)}"
......@@ -128,6 +130,17 @@ def time_duration(d: datetime.timedelta) -> str:
return "{} sekund".format(round(s))
def time_duration_numeric(d: datetime.timedelta) -> str:
s = round(d.total_seconds())
if s >= SECONDS_PER_DAY:
days = s // SECONDS_PER_DAY
s %= SECONDS_PER_DAY
prefix = f'{days}d+'
else:
prefix = ""
return f'{prefix}{s//3600:02d}:{(s//60)%60:02d}:{s%60:02d}'
def data_size(bytes: int) -> str:
if bytes is None:
return '0 B'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment