From 9df86aee72cda39c571107cc5490e2f21ebba386 Mon Sep 17 00:00:00 2001 From: toravest Date: Mon, 7 Apr 2025 12:34:01 +0200 Subject: [PATCH] changes function, standardvalue for hour and minute, if no input --- src/my_package/date_to_unix.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/my_package/date_to_unix.py b/src/my_package/date_to_unix.py index 92ea3ce..89da30b 100644 --- a/src/my_package/date_to_unix.py +++ b/src/my_package/date_to_unix.py @@ -11,16 +11,32 @@ def get_unix_timestamp(): start_year = int(start_date_components[0]) start_month = int(start_date_components[1]) start_date = int(start_date_components[2]) - start_hour = int(start_date_components[3]) - start_minute = int(start_date_components[4]) + + # Checks if hour and minute is inputed, if not value = 0 + if len(start_date_components) > 3: + start_hour = int(start_date_components[3]) + else: + start_hour = 00 + if len(start_date_components) > 4: + start_minute = int(start_date_components[4]) + else: + start_minute = 00 # Variables that splits and assign the end date values end_date_components = end_date_input.split(",") end_year = int(end_date_components[0]) end_month = int(end_date_components[1]) end_date = int(end_date_components[2]) - end_hour = int(end_date_components[3]) - end_minute = int(end_date_components[4]) + + # Checks if hour and minute is inputed, if not value = 0 + if len(end_date_components) > 3: + end_hour = int(end_date_components[3]) + else: + end_hour = 00 + if len(end_date_components) > 4: + end_minute = int(end_date_components[4]) + else: + end_minute = 00 # Converts dates to timestamp used to convert to unix, and print, with the user input start_date_timestamp = datetime.datetime(start_year, start_month, start_date, start_hour, start_minute)