From c15b79dd34cdcc8b88258c34b9dd8dfd14036750 Mon Sep 17 00:00:00 2001 From: Will Sheldon <114631109+wssheldon@users.noreply.github.com> Date: Wed, 26 Apr 2023 13:02:46 -0700 Subject: [PATCH] src/dispatch/plugins/dispatch_slack/case/interactive.py --- .../dispatch_slack/case/interactive.py | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/dispatch/plugins/dispatch_slack/case/interactive.py b/src/dispatch/plugins/dispatch_slack/case/interactive.py index 465729561786..3544449b0f21 100644 --- a/src/dispatch/plugins/dispatch_slack/case/interactive.py +++ b/src/dispatch/plugins/dispatch_slack/case/interactive.py @@ -592,11 +592,37 @@ def _create_snooze_filter( description = form_data[DefaultBlockIds.description_input] name = form_data[DefaultBlockIds.title_input] delta: str = form_data[DefaultBlockIds.relative_date_picker_input].value + # Check if the 'delta' string contains days + # Example: '1 day, 0:00:00' contains days, while '0:01:00' does not + if ", " in delta: + # Split the 'delta' string into days and time parts + # Example: '1 day, 0:00:00' -> days: '1 day' and time_str: '0:00:00' + days, time_str = delta.split(", ") + + # Extract the integer value of days from the days string + # Example: '1 day' -> 1 + days = int(days.split(" ")[0]) + else: + # If the 'delta' string does not contain days, set days to 0 + days = 0 + + # Directly assign the 'delta' string to the time_str variable + time_str = delta + + # Split the 'time_str' variable into hours, minutes, and seconds + # Convert each part to an integer + # Example: '0:01:00' -> hours: 0, minutes: 1, seconds: 0 + hours, minutes, seconds = [int(x) for x in time_str.split(":")] + + # Create a timedelta object using the extracted days, hours, minutes, and seconds delta = timedelta( - hours=int(delta.split(":")[0]), - minutes=int(delta.split(":")[1]), - seconds=int(delta.split(":")[2]), + days=days, + hours=hours, + minutes=minutes, + seconds=seconds, ) + + # Calculate the new date by adding the timedelta object to the current date and time date = datetime.now() + delta project = project_service.get(db_session=db_session, project_id=signal.project_id)