fix: allow short timewindows to parse events

pull/136/head
Martin Eigenmann 2024-09-09 12:16:40 +02:00
rodzic 4d29cedf30
commit a005d3a787
Nie znaleziono w bazie danych klucza dla tego podpisu
3 zmienionych plików z 137 dodań i 5 usunięć

Wyświetl plik

@ -365,12 +365,42 @@ def parse_events(
if type(s) is date and e.recurring == False:
f, t = start, end
elif type(s) is datetime and s.tzinfo:
f, t = datetime(
start.year, start.month, start.day, tzinfo=s.tzinfo
), datetime(end.year, end.month, end.day, tzinfo=s.tzinfo)
f = (
datetime(
start.year,
start.month,
start.day,
start.hour,
start.minute,
tzinfo=s.tzinfo,
)
if type(start) == datetime
else datetime(start.year, start.month, start.day, tzinfo=s.tzinfo)
)
t = (
datetime(
end.year,
end.month,
end.day,
end.hour,
end.minute,
tzinfo=s.tzinfo,
)
if type(end) == datetime
else datetime(end.year, end.month, end.day, tzinfo=s.tzinfo)
)
else:
f, t = datetime(start.year, start.month, start.day), datetime(
end.year, end.month, end.day
f = (
datetime(
start.year, start.month, start.day, start.hour, start.minute
)
if type(start) == datetime
else datetime(start.year, start.month, start.day)
)
t = (
datetime(end.year, end.month, end.day, end.hour, end.minute)
if type(end) == datetime
else datetime(end.year, end.month, end.day)
)
if e.recurring:

Wyświetl plik

@ -0,0 +1,91 @@
BEGIN:VCALENDAR
METHOD:PUBLISH
PRODID:Microsoft Exchange Server 2010
VERSION:2.0
X-WR-CALNAME:Calendar
BEGIN:VTIMEZONE
TZID:Pacific Standard Time
BEGIN:STANDARD
DTSTART:16010101T020000
TZOFFSETFROM:-0700
TZOFFSETTO:-0800
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:16010101T020000
TZOFFSETFROM:-0800
TZOFFSETTO:-0700
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VTIMEZONE
TZID:UTC
BEGIN:STANDARD
DTSTART:16010101T000000
TZOFFSETFROM:+0000
TZOFFSETTO:+0000
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:16010101T000000
TZOFFSETFROM:+0000
TZOFFSETTO:+0000
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VTIMEZONE
TZID:Central Standard Time
BEGIN:STANDARD
DTSTART:16010101T020000
TZOFFSETFROM:-0500
TZOFFSETTO:-0600
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:16010101T020000
TZOFFSETFROM:-0600
TZOFFSETTO:-0500
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VTIMEZONE
TZID:Eastern Standard Time
BEGIN:STANDARD
DTSTART:16010101T020000
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:16010101T020000
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VTIMEZONE
TZID:India Standard Time
BEGIN:STANDARD
DTSTART:16010101T000000
TZOFFSETFROM:+0530
TZOFFSETTO:+0530
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:16010101T000000
TZOFFSETFROM:+0530
TZOFFSETTO:+0530
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
UID:0400AAAA8200E00074C5B7101A82E0080000000085E5DC3409AAAA01000000000000000
010000000AAAADE08C53CAA4283D0AAA1A2AAA97
SUMMARY:TEST Summary
DTSTART;TZID=Pacific Standard Time:20230509T090000
DTEND;TZID=Pacific Standard Time:20230509T100000
CLASS:PUBLIC
PRIORITY:5
DTSTAMP:20230509T014745Z
TRANSP:OPAQUE
STATUS:CONFIRMED
SEQUENCE:0
LOCATION:
END:VEVENT
END:VCALENDAR

Wyświetl plik

@ -862,6 +862,17 @@ class ICalEventsTests(unittest.TestCase):
"starts at 5 utc summer time (+2:00)",
)
def test_small_time_frame(self):
ical = "test/test_data/small_time_frame.ics"
PT = gettz("America/Los_Angeles")
start = datetime(month=5, day=9, year=2023, tzinfo=PT)
end = datetime(month=5, day=9, year=2023, hour=23, tzinfo=PT)
events = icalevents.events(file=ical, start=start, end=end, strict=True)
self.assertEqual(len(events), 1, "1 events")
def test_regression_repeating_events_raise_an_error(self):
ical = "test/test_data/recurrence_tzinfo.ics"
start = date(2023, 1, 1)