2022-05-14 15:13:02 +05:30
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
def formatSeconds(seconds: int | float, joiner: Optional[str] = None) -> str:
|
2022-05-11 01:53:12 +05:30
|
|
|
seconds = round(seconds)
|
2024-08-30 20:29:02 +05:30
|
|
|
timeValues = { "h": seconds // 3600, "m": seconds // 60 % 60, "s": seconds % 60 }
|
2022-05-11 03:27:06 +05:30
|
|
|
if not joiner:
|
2022-05-11 01:53:12 +05:30
|
|
|
return "".join(str(v) + k for k, v in timeValues.items() if v > 0)
|
2022-05-11 03:27:06 +05:30
|
|
|
if timeValues["h"] == 0:
|
2022-05-11 01:53:12 +05:30
|
|
|
del timeValues["h"]
|
|
|
|
return joiner.join(str(v).rjust(2, "0") for v in timeValues.values())
|
2024-02-13 14:22:27 +05:30
|
|
|
|
|
|
|
def truncate(text: str, maxLength: int) -> str:
|
|
|
|
if len(text) > maxLength:
|
|
|
|
text = text[:maxLength-3] + "..."
|
|
|
|
return text
|