| 5 | |
| 6 | |
| 7 | def format_remaining_time(total_seconds: float) -> str: |
| 8 | if total_seconds < 0: |
| 9 | total_seconds = 0 |
| 10 | |
| 11 | days, remainder = divmod(total_seconds, 86400) |
| 12 | hours, remainder = divmod(remainder, 3600) |
| 13 | minutes, seconds = divmod(remainder, 60) |
| 14 | |
| 15 | days = int(days) |
| 16 | hours = int(hours) |
| 17 | minutes = int(minutes) |
| 18 | |
| 19 | parts = [] |
| 20 | if days > 0: |
| 21 | parts.append(f"{days}d") |
| 22 | if hours > 0: |
| 23 | parts.append(f"{hours}h") |
| 24 | if minutes > 0: |
| 25 | parts.append(f"{minutes}m") |
| 26 | |
| 27 | if days > 0 or hours > 0: |
| 28 | if seconds >= 1: |
| 29 | parts.append(f"{int(seconds)}s") |
| 30 | elif minutes > 0: |
| 31 | if seconds >= 0.1: |
| 32 | parts.append(f"{seconds:.1f}s") |
| 33 | else: |
| 34 | parts.append(f"{total_seconds:.1f}s") |
| 35 | |
| 36 | if not parts: |
| 37 | return "0.0s remaining" |
| 38 | |
| 39 | return " ".join(parts) + " remaining" |
| 40 | |
| 41 | |
| 42 | async def managed_wait(agent, target_time, is_duration_wait, log, get_heading_callback): |