MCPcopy
hub / github.com/langchain-ai/deepagents / format_duration

Function format_duration

libs/code/deepagents_code/formatting.py:19–37  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

17
18
19def 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
40def macos_force_24_hour_time() -> bool | None:

Callers 13

print_usage_tableFunction · 0.90
_format_timingFunction · 0.90
_update_animationMethod · 0.90
pauseMethod · 0.90
set_successMethod · 0.90
test_whole_secondsMethod · 0.90
test_minutesMethod · 0.90
test_hoursMethod · 0.90

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…