From 5106ee455c4f4a19776b1c1e50c9bf22d9f472e1 Mon Sep 17 00:00:00 2001 From: Egor Deev <67710823+IGlek@users.noreply.github.com> Date: Thu, 1 Feb 2024 21:55:40 +0400 Subject: [PATCH] v. 1.2 --- code/script.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/code/script.py b/code/script.py index 5a32f85..3a3ab37 100644 --- a/code/script.py +++ b/code/script.py @@ -38,9 +38,19 @@ def text_ical(user_id, tz): r_rule = component.get('rrule') if r_rule: list_rrule = icalendar.vRecur.to_ical(r_rule).decode('utf-8').split(';') + + until, u_flag = [elem for elem in list_rrule if 'UNTIL' in elem], True list_rrule = [elem for elem in list_rrule if 'UNTIL' not in elem] - until = "UNTIL=" + "".join(date.date().isoformat().split("-")) + "T235900Z" + if until: + until_old = until[0].split('=')[1] + until = isoparse(until_old).replace(tzinfo=None) + + if until.replace(tzinfo=None) <= date.replace(tzinfo=None): + until, u_flag = "UNTIL=" + until_old, False + + if u_flag: + until = "UNTIL=" + "".join(date.date().isoformat().split("-")) + "T235900Z" list_rrule.append(until) list_rrule = ";".join(list_rrule)