Format a duration in seconds as hours, minutes, and seconds (e.g. ``1h 2m 3.45s``, ``45.67s``).
(total_seconds: int)
| 17 | |
| 18 | |
| 19 | def format_duration_hms(total_seconds: int) -> str: |
| 20 | """Format a duration in seconds as hours, minutes, and seconds (e.g. ``1h 2m 3.45s``, ``45.67s``).""" |
| 21 | if total_seconds < 0: |
| 22 | total_seconds = 0 |
| 23 | h = int(total_seconds // 3600) |
| 24 | m = int((total_seconds % 3600) // 60) |
| 25 | s = total_seconds % 60 |
| 26 | if h: |
| 27 | return f"{h}h {m}m {s}s" |
| 28 | if m: |
| 29 | return f"{m}m {s}s" |
| 30 | text = f"{s}".rstrip("0").rstrip(".") |
| 31 | return f"{text}s" if text else "0s" |
| 32 | |
| 33 | |
| 34 | AMBIGUITY_CAUSES = { |
no outgoing calls
no test coverage detected