diff options
Diffstat (limited to 'challenge-100/lubos-kolouch/python/ch-1.py')
| -rw-r--r-- | challenge-100/lubos-kolouch/python/ch-1.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-100/lubos-kolouch/python/ch-1.py b/challenge-100/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..5c5eee47d8 --- /dev/null +++ b/challenge-100/lubos-kolouch/python/ch-1.py @@ -0,0 +1,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' |
