MCPcopy Create free account
hub / github.com/geekcomputers/Python / convert_time

Function convert_time

convert_time.py:6–23  ·  view source on GitHub ↗
(input_str)

Source from the content-addressed store, hash-verified

4
5
6def convert_time(input_str):
7 # Checking if last two elements of time
8 # is AM and first two elements are 12
9 if input_str[-2:] == "AM" and input_str[:2] == "12":
10 return "00" + input_str[2:-2]
11
12 # remove the AM
13 elif input_str[-2:] == "AM":
14 return input_str[:-2]
15
16 # Checking if last two elements of time
17 # is PM and first two elements are 12
18 elif input_str[-2:] == "PM" and input_str[:2] == "12":
19 return input_str[:-2]
20
21 else:
22 # add 12 to hours and remove PM
23 return str(int(input_str[:2]) + 12) + input_str[2:8]
24
25
26if __name__ == "__main__":

Callers 1

convert_time.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected