minor fixes
This commit is contained in:
parent
3d99247c01
commit
4f0e5d5549
1 changed files with 14 additions and 5 deletions
|
|
@ -1093,12 +1093,19 @@ def get_archive_id(url: str) -> tuple[bool, dict[str | None, str | None, str | N
|
||||||
|
|
||||||
def dt_delta(delta: timedelta) -> str:
|
def dt_delta(delta: timedelta) -> str:
|
||||||
"""
|
"""
|
||||||
Turn a timedelta into “1d 20h 5min” style output.
|
Convert a timedelta object to a human-readable string.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
delta (timedelta): The timedelta object.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: A human-readable string representing the timedelta.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
total_secs = int(delta.total_seconds())
|
total_secs = int(delta.total_seconds())
|
||||||
days, rem = divmod(total_secs, 86400)
|
days, rem = divmod(total_secs, 86400)
|
||||||
hours, rem = divmod(rem, 3600)
|
hours, rem = divmod(rem, 3600)
|
||||||
minutes = rem // 60
|
minutes, secs = divmod(rem, 60)
|
||||||
|
|
||||||
parts = []
|
parts = []
|
||||||
if days:
|
if days:
|
||||||
|
|
@ -1106,10 +1113,12 @@ def dt_delta(delta: timedelta) -> str:
|
||||||
if hours:
|
if hours:
|
||||||
parts.append(f"{hours}h")
|
parts.append(f"{hours}h")
|
||||||
if minutes:
|
if minutes:
|
||||||
parts.append(f"{minutes}min")
|
parts.append(f"{minutes}m")
|
||||||
|
if secs:
|
||||||
|
parts.append(f"{secs}s")
|
||||||
|
|
||||||
# if it's under one minute:
|
# if it's under one second
|
||||||
if not parts:
|
if not parts:
|
||||||
parts.append("0min")
|
parts.append("<1s")
|
||||||
|
|
||||||
return " ".join(parts)
|
return " ".join(parts)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue