From bfd02fb1bed5fbe58b7ae626e7ad8a8bb4bf756c Mon Sep 17 00:00:00 2001 From: Alexander PapaTutuWawa Date: Sun, 7 Mar 2021 15:32:07 +0100 Subject: [PATCH] feat: Pad time --- janine/utils.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/janine/utils.py b/janine/utils.py index 8ef4fb8..902b9b9 100644 --- a/janine/utils.py +++ b/janine/utils.py @@ -30,6 +30,15 @@ def make_msg(to, body): return msg +def pad_time_component(c): + ''' + If we have 12:08, it gets turned into 12:8, so we need to pad + the components with a leading zero, if there is none. + ''' + if len(c) != 2: + return f'0{c}' + return c + def format_time(time_str): ''' Reformat ISO style time data to a more @@ -40,7 +49,7 @@ def format_time(time_str): except ValueError: return time_str - return f'{date.day}.{date.month}.{date.year} {date.hour}:{date.minute}' + return f'{date.day}.{date.month}.{date.year} {pad_time_component(date.hour)}:{pad_time_component(date.minute)}' def format_warning(warning): '''