MCPcopy Create free account
hub / github.com/dbunt1tled/python-fast-api / format_time

Function format_time

src/core/service/statistics.py:33–62  ·  view source on GitHub ↗
(s: int | float)

Source from the content-addressed store, hash-verified

31
32
33def format_time(s: int | float) -> str:
34 if s < 1:
35 if s > 0.001:
36 return f"{s * 1000:.2f} ms"
37 else:
38 return f"{s * 1000000:.0f} us"
39
40 td = timedelta(seconds=s)
41
42 if td.days > 0:
43 if td.days == 1:
44 return "1 day"
45 return f"{td.days} days"
46
47 hours = td.seconds // 3600
48 if hours > 0:
49 if hours == 1:
50 return "1 hr"
51 return f"{hours} hrs"
52
53 minutes = (td.seconds % 3600) // 60
54 if minutes > 0:
55 if minutes == 1:
56 return "1 min"
57 return f"{minutes} mins"
58
59 seconds = td.seconds % 60
60 if seconds == 1:
61 return "1 sec"
62 return f"{seconds} sec"
63
64
65def render_statistics(start_time: int | float) -> str:

Callers 1

render_statisticsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected