Format a duration in seconds into a human-readable string. Args: seconds: Duration in seconds. Returns: Formatted string like `"5s"`, `"2.3s"`, `"5m 12s"`, or `"1h 23m 4s"`.
(seconds: float)
| 17 | |
| 18 | |
| 19 | def format_duration(seconds: float) -> str: |
| 20 | """Format a duration in seconds into a human-readable string. |
| 21 | |
| 22 | Args: |
| 23 | seconds: Duration in seconds. |
| 24 | |
| 25 | Returns: |
| 26 | Formatted string like `"5s"`, `"2.3s"`, `"5m 12s"`, or `"1h 23m 4s"`. |
| 27 | """ |
| 28 | rounded = round(seconds, 1) |
| 29 | if rounded < 60: # noqa: PLR2004 |
| 30 | if rounded % 1 == 0: |
| 31 | return f"{int(rounded)}s" |
| 32 | return f"{rounded:.1f}s" |
| 33 | minutes, secs = divmod(int(rounded), 60) |
| 34 | if minutes < 60: # noqa: PLR2004 |
| 35 | return f"{minutes}m {secs}s" |
| 36 | hours, minutes = divmod(minutes, 60) |
| 37 | return f"{hours}h {minutes}m {secs}s" |
| 38 | |
| 39 | |
| 40 | def macos_force_24_hour_time() -> bool | None: |
no outgoing calls
searching dependent graphs…