mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-10 20:27:03 +01:00
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint) (push) Waiting to run
Tests / test (push) Waiting to run
Tests / web-coverage (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
28 lines
877 B
Python
28 lines
877 B
Python
"""Countdown label for time left on a lock, e.g. "2w 2d" or "1h 8m"."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import math
|
|
|
|
# Largest first; weeks are the top unit because months vary in length.
|
|
_UNITS = (("w", 7 * 86400), ("d", 86400), ("h", 3600), ("m", 60), ("s", 1))
|
|
|
|
|
|
def fmt_remaining(seconds: float) -> str:
|
|
"""Format *seconds* as its two largest units, down to one second.
|
|
|
|
Rounds up, so the label reads "0s" only once the time is actually up.
|
|
|
|
Args:
|
|
seconds: Time left; negative counts as zero.
|
|
|
|
Returns:
|
|
A label such as "2w 2d", "2d 14h", "2h 20m", "5m 7s" or "45s".
|
|
"""
|
|
left = max(0, math.ceil(seconds))
|
|
for i, (name, size) in enumerate(_UNITS[:-1]):
|
|
if left >= size:
|
|
sub_name, sub_size = _UNITS[i + 1]
|
|
return f"{left // size}{name} {left % size // sub_size}{sub_name}"
|
|
return f"{left}s"
|