MCPcopy Create free account
hub / github.com/dbcli/mycli / format_uptime

Function format_uptime

mycli/packages/special/utils.py:30–58  ·  view source on GitHub ↗

Format number of seconds into human-readable string. :param uptime_in_seconds: The server uptime in seconds. :returns: A human-readable string representing the uptime. >>> uptime = format_uptime('56892') >>> print(uptime) 15 hours 48 min 12 sec

(uptime_in_seconds: str)

Source from the content-addressed store, hash-verified

28
29
30def format_uptime(uptime_in_seconds: str) -> str:
31 """Format number of seconds into human-readable string.
32
33 :param uptime_in_seconds: The server uptime in seconds.
34 :returns: A human-readable string representing the uptime.
35
36 >>> uptime = format_uptime('56892')
37 >>> print(uptime)
38 15 hours 48 min 12 sec
39 """
40
41 m, s = divmod(int(uptime_in_seconds), 60)
42 h, m = divmod(m, 60)
43 d, h = divmod(h, 24)
44
45 uptime_values: list[str] = []
46
47 for value, unit in ((d, "days"), (h, "hours"), (m, "min"), (s, "sec")):
48 if value == 0 and not uptime_values:
49 # Don't include a value/unit if the unit isn't applicable to
50 # the uptime. E.g. don't do 0 days 0 hours 1 min 30 sec.
51 continue
52 if value == 1 and unit.endswith("s"):
53 # Remove the "s" if the unit is singular.
54 unit = unit[:-1]
55 uptime_values.append(f'{value} {unit}')
56
57 uptime = " ".join(uptime_values)
58 return uptime
59
60
61def get_uptime(cur: Cursor) -> int:

Callers 4

statusFunction · 0.90
render_prompt_stringFunction · 0.90
test_format_uptimeFunction · 0.90

Calls 1

joinMethod · 0.80

Tested by 2

test_format_uptimeFunction · 0.72