niccokunzmann / python-recurring-ical-events

Python library to calculate recurrence times of events, todos and journals based on icalendar RFC5545
https://pypi.org/project/recurring-ical-events/
GNU Lesser General Public License v3.0
92 stars 20 forks source link

reproduce issue 151 #153

Closed niccokunzmann closed 1 month ago

niccokunzmann commented 2 months ago

This PR tries to reproduce Issue #151.

sanieldalib commented 2 months ago

@niccokunzmann There is 1 event expected from this test:

✗ python3 test.py 
Found 1 events
[VEVENT({'DTSTART': vDDDTypes(2024-08-01 19:00:00-07:00, Parameters({'TZID': 'America/Los_Angeles'})), 'DTEND': vDDDTypes(2024-08-01 20:00:00-07:00, Parameters({'TZID': 'America/Los_Angeles'})), 'DTSTAMP': vDDDTypes(2024-08-07 00:03:26+00:00, Parameters({})), 'UID': vText('b'aogpprh4bolu8ckmop49ca6404@google.com''), 'CREATED': vDDDTypes(2014-03-31 19:26:50+00:00, Parameters({})), 'LAST-MODIFIED': vDDDTypes(2015-07-31 02:23:26+00:00, Parameters({})), 'SEQUENCE': 1, 'STATUS': vText('b'CONFIRMED''), 'SUMMARY': vText('b'Vespers for the Feast of St. Joseph''), 'TRANSP': vText('b'OPAQUE'')}, VALARM({'ACTION': vText('b'NONE''), 'TRIGGER': vDDDTypes(1976-04-01 00:55:45+00:00, Parameters({'VALUE': 'DATE-TIME'})), 'X-WR-ALARMUID': vText('b'0D3A9816-AC61-499A-A594-930AA281666B''), 'UID': vText('b'0D3A9816-AC61-499A-A594-930AA281666B'')}))]
niccokunzmann commented 1 month ago

In 946e894, I checked...

$ tox -e py39 -- test/test_issue_151_macos_linux_difference.py::test_count_events_from_issue[Calendars-use_pytz] test/test_issue_151_macos_linux_difference.py::test_check_event_count_for_that_day[ReversedCalendars-use_zoneinfo]

py39: commands[0]> pytest --basetemp=/home/nicco/recurring-ical-events/.tox/py39/tmp 'test/test_issue_151_macos_linux_difference.py::test_count_events_from_issue[Calendars-use_pytz]' 'test/test_issue_151_macos_linux_difference.py::test_check_event_count_for_that_day[ReversedCalendars-use_zoneinfo]'
============================================================== test session starts ===============================================================
platform linux -- Python 3.9.18, pytest-8.2.2, pluggy-1.5.0
cachedir: .tox/py39/.pytest_cache
rootdir: /home/nicco/recurring-ical-events
configfile: pyproject.toml
plugins: cov-5.0.0
collected 2 items                                                                                                                                

test/test_issue_151_macos_linux_difference.py FF                                                                                           [100%]

==================================================================== FAILURES ====================================================================
________________________________________________ test_count_events_from_issue[Calendars-use_pytz] ________________________________________________

calendars = Calendars(use_pytz)

    def test_count_events_from_issue(calendars):
        """Avents were omitted through version upgrade from 2.2.2 to 2.2.3."""

        start_time = datetime.fromtimestamp(1722564000, timezone.utc)
        end_time = datetime.fromtimestamp(1722567600, timezone.utc)
        print(f"from {start_time.timestamp()} to {end_time.timestamp()}")
        events = calendars.issue_151_macos_linux_difference.between(start_time, end_time)
        for event in events:
            print(event["UID"], event["DTSTART"], event["SUMMARY"])
>       assert len(events) == 1
E       assert 0 == 1
E        +  where 0 = len([])

test/test_issue_151_macos_linux_difference.py:18: AssertionError
-------------------------------------------------------------- Captured stdout call --------------------------------------------------------------
from 1722564000.0 to 1722567600.0
<recurring_ical_events.RepeatedEvent object at 0x75baf718f970>
other 2014-08-01 None <class 'datetime.date'>
added event!
remove_because_not_in_span 1 [VEVENT({'DTSTART': vDDDTypes(2014-08-01 18:30:00-07:00, Parameters({'TZID': 'America/Los_Angeles'})), 'DTEND': vDDDTypes(2014-08-01 19:30:00-07:00, Parameters({'TZID': 'America/Los_Angeles'})), 'DTSTAMP': vDDDTypes(2024-08-07 00:03:26+00:00, Parameters({})), 'UID': vText(b'aogpprh4bolu8ckmop49ca6404@google.com'), 'RECURRENCE-ID': vDDDTypes(2014-08-01 19:00:00-07:00, Parameters({'TZID': 'America/Los_Angeles'})), 'CREATED': vDDDTypes(2014-03-31 19:26:50+00:00, Parameters({})), 'LAST-MODIFIED': vDDDTypes(2015-07-31 02:23:26+00:00, Parameters({})), 'SEQUENCE': 3, 'STATUS': vText(b'CONFIRMED'), 'SUMMARY': vText(b'Vespers for the Feast of St. Joseph'), 'TRANSP': vText(b'OPAQUE')}, VALARM({'ACTION': vText(b'NONE'), 'TRIGGER': vDDDTypes(1976-04-01 00:55:45+00:00, Parameters({'VALUE': 'DATE-TIME'})), 'X-WR-ALARMUID': vText(b'8744D632-C9F8-483C-B095-590E0A3D2E39'), 'UID': vText(b'8744D632-C9F8-483C-B095-590E0A3D2E39')}))]
______________________________________ test_check_event_count_for_that_day[ReversedCalendars-use_zoneinfo] _______________________________________

calendars = ReversedCalendars(use_zoneinfo)

    def test_check_event_count_for_that_day(calendars):
        """Avents were omitted through version upgrade from 2.2.2 to 2.2.3."""

        events = calendars.issue_151_macos_linux_difference.at("20140801")
        for event in events:
            print(event["UID"], event["DTSTART"], event["SUMMARY"], event["DTSTART"].dt.timestamp())
>       assert len(events) == 1 and False
E       AssertionError: assert (1 == 1 and False)
E        +  where 1 = len([VEVENT({'DTSTART': vDDDTypes(2014-08-01 18:30:00-07:00, Parameters({'TZID': 'America/Los_Angeles'})), 'DTEND': vDDDTy...WR-ALARMUID': vText(b'8744D632-C9F8-483C-B095-590E0A3D2E39'), 'UID': vText(b'8744D632-C9F8-483C-B095-590E0A3D2E39')}))])

test/test_issue_151_macos_linux_difference.py:26: AssertionError
-------------------------------------------------------------- Captured stdout call --------------------------------------------------------------
<recurring_ical_events.RepeatedEvent object at 0x75baf719d850>
other 2014-08-01 None <class 'datetime.date'>
added event!
remove_because_not_in_span 0 []
aogpprh4bolu8ckmop49ca6404@google.com vDDDTypes(2014-08-01 18:30:00-07:00, Parameters({'TZID': 'America/Los_Angeles'})) Vespers for the Feast of St. Joseph 1406943000.0
============================================================ short test summary info =============================================================
FAILED test/test_issue_151_macos_linux_difference.py::test_count_events_from_issue[Calendars-use_pytz] - assert 0 == 1
FAILED test/test_issue_151_macos_linux_difference.py::test_check_event_count_for_that_day[ReversedCalendars-use_zoneinfo] - AssertionError: assert (1 == 1 and False)
=============================================================== 2 failed in 0.11s ================================================================
py39: exit 1 (0.33 seconds) /home/nicco/recurring-ical-events> pytest --basetemp=/home/nicco/recurring-ical-events/.tox/py39/tmp 'test/test_issue_151_macos_linux_difference.py::test_count_events_from_issue[Calendars-use_pytz]' 'test/test_issue_151_macos_linux_difference.py::test_check_event_count_for_that_day[ReversedCalendars-use_zoneinfo]' pid=53075
  py39: FAIL code 1 (0.37=setup[0.04]+cmd[0.33] seconds)
  evaluation failed :( (0.44 seconds)

The event is present on that day but absent in the window that you ask for...

The event is listed but as not within the span, see this line: remove_because_not_in_span 1

niccokunzmann commented 1 month ago

This is weird ... I go the error down to this:

event_start < span_stop: 2014-08-01 18:30:00-07:00 < 2024-08-01 20:00:00-07:00 == True
and span_start < event_stop: 2024-08-01 19:00:00-07:00 < 2014-08-01 19:30:00-07:00 == False

The last line evaluates to False although it is clearly True: 19:00 is before 19:30

tox -e py39 -- test/test_time_span_contains_event.py

in 0d64f85

niccokunzmann commented 1 month ago

Uh, the difference is 2024 and 2014

The issue lies somewhere else then... The yearly rrule does not seem to include the event then...

niccokunzmann commented 1 month ago

Ok... I found it! What happened: In the last issue we fixed, we made sure that edits are not ignored. In this issue, we face the problem that edits of an event occurrence within a sequence now override the base event and its repetition rules. Thanks for reporting this! This can be solved and best also includes a refactoring of where recurrences are calculated.

sanieldalib commented 1 month ago

My pleasure! Thanks for getting to the bottom of this

niccokunzmann commented 1 month ago

So, I did a big refactoring that was due. This breaks a little the promised interface. Thus, the major version number will be increased.