From 72adb809a4d4375334f9530b0f890c480f64ea11 Mon Sep 17 00:00:00 2001 From: xelast418 Date: Sat, 23 Sep 2023 20:11:10 +1200 Subject: [PATCH] Fixes modify/shift to allow a negative time shift --- app/tools/tools.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/tools/tools.py b/app/tools/tools.py index 5bc7348..c9f6154 100644 --- a/app/tools/tools.py +++ b/app/tools/tools.py @@ -196,9 +196,16 @@ def modify_time(cal: Calendar, modify: dict) -> Calendar: hour = 0 if not ("hour" in shift) else shift["hour"] minute = 0 if not ("minute" in shift) else shift["minute"] - for event in cal.events: - event.end = event.end.shift(years=year, months=month, days=day, hours=hour, minutes=minute) - event.begin = event.begin.shift(years=year, months=month, days=day, hours=hour, minutes=minute) + shift_minutes = (year * 365 * 24 * 60) + (month * 30 * 24 * 60) + (day * 24 * 60) + (hour * 60) + minute + + if shift_minutes > 0: + for event in cal.events: + event.end = event.end.shift(minutes=shift_minutes) + event.begin = event.begin.shift(minutes=shift_minutes) + elif shift_minutes < 0: + for event in cal.events: + event.begin = event.begin.shift(minutes=shift_minutes) + event.end = event.end.shift(minutes=shift_minutes) return cal