aboutsummaryrefslogtreecommitdiff
path: root/challenge-100/lubos-kolouch/python/ch-1.py
blob: 5c5eee47d8697d825d75b9e6a81d5a1ce11c91fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/python
"""
#===============================================================================
#
#         FILE: ch-1.py
#
#        USAGE: ./ch-1.py
#
#  DESCRIPTION: Perl Weekly Challenge #100
#               Task 1
#       AUTHOR: Lubos Kolouch
#      CREATED: 02/20/2021 10:16:51 AM
#===============================================================================
"""
from time import strptime, strftime


def convert_time(inp_time):
    """ Convert the time as required """

    new_time = inp_time.replace(" ", "")
    parse_pattern = '%H:%M' if 'm' not in inp_time else '%I:%M%p'
    out_pattern = '%H:%M' if 'm' in inp_time else '%I:%M%p'

    conv_time = strptime(new_time, parse_pattern)
    return strftime(out_pattern, conv_time)


assert convert_time('05:15pm') == '17:15'
assert convert_time('05:15 pm') == '17:15'
assert convert_time('19:15') == '07:15PM'