niccokunzmann / python-recurring-ical-events

Python library for recurrence of ical events based on icalendar

Home Page:https://pypi.org/project/recurring-ical-events/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bug: recurring event series that start in daylight savings time and end in standard time

natashamm opened this issue · comments

Describe the bug

Using a calendar application, I created a weekly event series in Pacific Standard Time that begins on January 5th and ends on June 8th. I filtered out events using between from today's date (~January 2023) and 1 year in the future (~January 2024). However, it incorrectly omitted the last event in the series on June 8th.

Upon further investigation, it seems to just be an issue for a recurring event series that begin in standard time but end in daylight savings time.

To Reproduce

Here is a simple script I used to test the issue.

import icalendar
import recurring_ical_events
import datetime

TODAY = datetime.datetime.today().date()
FUTURE = TODAY + datetime.timedelta(days=365)
if __name__ == "__main__":
    with open('calendar.ics', 'r') as f:
        cal_text = f.read()
    cal = icalendar.Calendar.from_ical(cal_text)
    events = recurring_ical_events.of(cal).between(TODAY, FUTURE)
    for event in events: print(event.get('dtstart').dt)

latest date will be 2023-06-01 10:00:00-07:00

ICS file

calendar.ics

BEGIN:VCALENDAR
PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN
VERSION:2.0
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:VEVENT
RRULE:FREQ=WEEKLY;UNTIL=20230608T170000Z;INTERVAL=1;BYDAY=TH;WKST=SU
DTSTART;TZID=Pacific Standard Time:20230105T100000
DTEND;TZID=Pacific Standard Time:20230105T110000
END:VEVENT
END:VCALENDAR

Expected behavior

I would expect it to include an event on 2023-06-08 10:00:00-07:00

  1. that is how it is displayed when you open the .ics file in a calendar application
  2. recurring event series that start and end before a change to Daylight Savings Time do not seem to have this issue

Version:

Suggested implementation

@natashamm thanks! It is good that you caught this and I am very happy with how you reported it and I can say: Yes, this is a bug! #108 reproduces the problem. I do not have time now but a pull request can be made to the branch issue-107 to make it green and merge into master.

The fix is deployed from version 2.0.2 on. You can update and install it.