MCPcopy Index your code
hub / github.com/geekcomputers/Python / clock_diff

Function clock_diff

Timetable_Operations.py:20–32  ·  view source on GitHub ↗

Return difference between t1 and t2 as HH:MM:SS (zero-padded).

(t1: str, t2: str)

Source from the content-addressed store, hash-verified

18
19
20def clock_diff(t1: str, t2: str) -> str:
21 """Return difference between t1 and t2 as HH:MM:SS (zero-padded)."""
22 h1, m1, s1 = int(t1[0:2]), int(t1[3:5]), int(t1[6:8])
23 h2, m2, s2 = int(t2[0:2]), int(t2[3:5]), int(t2[6:8])
24 sec1 = h1 * 3600 + m1 * 60 + s1
25 sec2 = h2 * 3600 + m2 * 60 + s2
26 diff = sec2 - sec1
27 if diff < 0:
28 diff += 24 * 3600
29 h = diff // 3600
30 m = (diff % 3600) // 60
31 s = diff % 60
32 return f"{h:02}:{m:02}:{s:02}"
33
34
35def calculate() -> None:

Callers 1

calculateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected