nextcloud / server

☁️ Nextcloud server, a safe home for all your data
https://nextcloud.com
GNU Affero General Public License v3.0
27.44k stars 4.08k forks source link

OCP\Calendar\IManager::search with options lists all recurring events even outside search range #25734

Closed dartcafe closed 1 year ago

dartcafe commented 3 years ago

actual behavior

The return is a list of events within this timespan but also a list with all(!) recurring dates, whether they have an event in the timerange or not. I guess, these are events with the first occurrency before the timespan and the last after the timespan. Additionally only the timestamps of the first occurrency is available. Interpreting the recurring rules gets to complex tbh.

One time events get returned correctly.

Expected behavior

more info

Calling OCP\Calendar\IManager::search('', ['SUMMARY'], ['timerange' => ['start' => $from, 'end' => $to]]); where $from and $to are objects of DateTime

Affected code https://github.com/nextcloud/polls/blob/649c90415d3b3007e6576b880d78947f551c4aaa/lib/Service/CalendarService.php#L58-L84

Example:

json_encode($from)  {"date":"2021-03-03 10:00:00.000000","timezone_type":3,"timezone":"UTC"}
json_encode($to): = {"date":"2021-03-03 12:00:00.000000","timezone_type":3,"timezone":"UTC"}

As a result we get dates outside the defined timerange:

See also https://github.com/nextcloud/polls/issues/1185, where all birthdays were returned.

Complete result:

[{
    "id": "50",
    "type": "VEVENT",
    "uid": "fda60c8d-b8f4-4fa4-b7a9-69af79b0d118",
    "uri": "1B2F0370-19B6-42BD-9FA2-746FC509B0FE.ics",
    "objects": [{
        "CREATED": [{
                "date": "2021-01-25 16:29:07.000000",
                "timezone_type": 3,
                "timezone": "UTC"
            },
            []
        ],
        "DTSTAMP": [{
                "date": "2021-02-05 19:41:07.000000",
                "timezone_type": 3,
                "timezone": "UTC"
            },
            []
        ],
        "LAST-MODIFIED": [{
                "date": "2021-02-05 19:41:07.000000",
                "timezone_type": 3,
                "timezone": "UTC"
            },
            []
        ],
        "SEQUENCE": [6, []],
        "UID": ["fda60c8d-b8f4-4fa4-b7a9-69af79b0d118", []],
        "DTSTART": [{
            "date": "2021-02-16 13:00:00.000000",
            "timezone_type": 3,
            "timezone": "Europe\/Berlin"
        }, {
            "TZID": "Europe\/Berlin"
        }],
        "DTEND": [{
            "date": "2021-02-16 14:10:00.000000",
            "timezone_type": 3,
            "timezone": "Europe\/Berlin"
        }, {
            "TZID": "Europe\/Berlin"
        }],
        "SUMMARY": ["Phone call with Donald", []],
        "RRULE": ["FREQ=WEEKLY;BYDAY=TU;UNTIL=20211227T230000Z", []]
    }],
    "timezones": [{
        "DAYLIGHT": [{
            "TZOFFSETFROM": [
                ["+0100", []]
            ],
            "TZOFFSETTO": [
                ["+0200", []]
            ],
            "TZNAME": [
                ["CEST", []]
            ],
            "DTSTART": [
                [{
                        "date": "1970-03-29 02:00:00.000000",
                        "timezone_type": 3,
                        "timezone": "UTC"
                    },
                    []
                ]
            ],
            "RRULE": [
                ["FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU", []]
            ]
        }],
        "STANDARD": [{
            "TZOFFSETFROM": [
                ["+0200", []]
            ],
            "TZOFFSETTO": [
                ["+0100", []]
            ],
            "TZNAME": [
                ["CET", []]
            ],
            "DTSTART": [
                [{
                        "date": "1970-10-25 03:00:00.000000",
                        "timezone_type": 3,
                        "timezone": "UTC"
                    },
                    []
                ]
            ],
            "RRULE": [
                ["FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU", []]
            ]
        }],
        "TZID": ["Europe\/Berlin", []]
    }]
}, {
    "id": "53",
    "type": "VEVENT",
    "uid": "14114df6-d63f-4ef2-ae71-ff9b9262c86f",
    "uri": "B08DB277-5222-4643-932C-A22085B0295A.ics",
    "objects": [{
        "CREATED": [{
                "date": "2021-02-05 19:45:13.000000",
                "timezone_type": 3,
                "timezone": "UTC"
            },
            []
        ],
        "DTSTAMP": [{
                "date": "2021-02-05 19:46:32.000000",
                "timezone_type": 3,
                "timezone": "UTC"
            },
            []
        ],
        "LAST-MODIFIED": [{
                "date": "2021-02-05 19:46:32.000000",
                "timezone_type": 3,
                "timezone": "UTC"
            },
            []
        ],
        "SEQUENCE": [3, []],
        "UID": ["14114df6-d63f-4ef2-ae71-ff9b9262c86f", []],
        "DTSTART": [{
            "date": "2021-02-18 20:00:00.000000",
            "timezone_type": 3,
            "timezone": "Europe\/Berlin"
        }, {
            "TZID": "Europe\/Berlin"
        }],
        "DTEND": [{
            "date": "2021-02-18 22:30:00.000000",
            "timezone_type": 3,
            "timezone": "Europe\/Berlin"
        }, {
            "TZID": "Europe\/Berlin"
        }],
        "SUMMARY": ["Dinner with Secret", []],
        "RRULE": ["FREQ=WEEKLY;BYDAY=TH;UNTIL=20211229T230000Z", []]
    }],
    "timezones": [{
        "DAYLIGHT": [{
            "TZOFFSETFROM": [
                ["+0100", []]
            ],
            "TZOFFSETTO": [
                ["+0200", []]
            ],
            "TZNAME": [
                ["CEST", []]
            ],
            "DTSTART": [
                [{
                        "date": "1970-03-29 02:00:00.000000",
                        "timezone_type": 3,
                        "timezone": "UTC"
                    },
                    []
                ]
            ],
            "RRULE": [
                ["FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU", []]
            ]
        }],
        "STANDARD": [{
            "TZOFFSETFROM": [
                ["+0200", []]
            ],
            "TZOFFSETTO": [
                ["+0100", []]
            ],
            "TZNAME": [
                ["CET", []]
            ],
            "DTSTART": [
                [{
                        "date": "1970-10-25 03:00:00.000000",
                        "timezone_type": 3,
                        "timezone": "UTC"
                    },
                    []
                ]
            ],
            "RRULE": [
                ["FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU", []]
            ]
        }],
        "TZID": ["Europe\/Berlin", []]
    }]
}, {
    "id": "57",
    "type": "VEVENT",
    "uid": "4db07993-7a05-4570-8dd3-4a82a1a1e7c1",
    "uri": "67CBF600-27C7-407F-979C-FD291BD0DEFD.ics",
    "objects": [{
        "CREATED": [{
                "date": "2021-02-20 13:27:34.000000",
                "timezone_type": 3,
                "timezone": "UTC"
            },
            []
        ],
        "DTSTAMP": [{
                "date": "2021-02-20 13:28:16.000000",
                "timezone_type": 3,
                "timezone": "UTC"
            },
            []
        ],
        "LAST-MODIFIED": [{
                "date": "2021-02-20 13:28:16.000000",
                "timezone_type": 3,
                "timezone": "UTC"
            },
            []
        ],
        "SEQUENCE": [2, []],
        "UID": ["4db07993-7a05-4570-8dd3-4a82a1a1e7c1", []],
        "DTSTART": [{
            "date": "2021-01-31 00:00:00.000000",
            "timezone_type": 3,
            "timezone": "UTC"
        }, {
            "VALUE": "DATE"
        }],
        "DTEND": [{
            "date": "2021-02-01 00:00:00.000000",
            "timezone_type": 3,
            "timezone": "UTC"
        }, {
            "VALUE": "DATE"
        }],
        "SUMMARY": ["Monthly", []],
        "RRULE": ["FREQ=MONTHLY;COUNT=12;BYMONTHDAY=31", []]
    }],
    "timezones": []
}, {
    "id": "58",
    "type": "VEVENT",
    "uid": "1ce9cba9-0954-4c22-b577-6d0a8ffde7dd",
    "uri": "AC5FFE15-B504-4247-9907-AC94CB2256DD.ics",
    "objects": [{
        "CREATED": [{
                "date": "2021-02-20 13:28:39.000000",
                "timezone_type": 3,
                "timezone": "UTC"
            },
            []
        ],
        "DTSTAMP": [{
                "date": "2021-02-20 13:29:11.000000",
                "timezone_type": 3,
                "timezone": "UTC"
            },
            []
        ],
        "LAST-MODIFIED": [{
                "date": "2021-02-20 13:29:11.000000",
                "timezone_type": 3,
                "timezone": "UTC"
            },
            []
        ],
        "SEQUENCE": [2, []],
        "UID": ["1ce9cba9-0954-4c22-b577-6d0a8ffde7dd", []],
        "DTSTART": [{
            "date": "2021-01-01 00:00:00.000000",
            "timezone_type": 3,
            "timezone": "UTC"
        }, {
            "VALUE": "DATE"
        }],
        "DTEND": [{
            "date": "2021-01-02 00:00:00.000000",
            "timezone_type": 3,
            "timezone": "UTC"
        }, {
            "VALUE": "DATE"
        }],
        "SUMMARY": ["Monatlich 1", []],
        "RRULE": ["FREQ=MONTHLY;COUNT=12;BYMONTHDAY=1", []]
    }],
    "timezones": []
}]
szaimen commented 3 years ago

I suppose this is still valid on NC21.0.2?

dartcafe commented 3 years ago

I guess, yes.

dartcafe commented 3 years ago

Just tested this. This is still a problem. I am not able to identify recurring events belonging to a certain time span using OCP\Calendar\IManager::search() and OCP\Calendar\ICalendar

There are still two problems when searching for events:

  1. I get all events with a starting datetime before the searched ending datetime and an ending datetime of the last occurance after the searched starting datetime. At least it seems so.
  2. I can't identify matching events, if they are recurring events because only the event's initial datetimes are delivered, but not the matching datetimes. Interpreting the RRULE seems a little bit too heavy.

At the moment, I have to filter out recurrences from the response, to avoid

What would be the perfect solution:

  1. Search only delivers recurring events with a recurrence matching to the searched time span (recurrence starting datetime before the searched ending datetime and recurrence ending datetime after the searched starting datetime)
  2. additionally deliver the recurrence actual datetime information

To be respected: There could be more than one recurrences of an event inside the searched sidespan.

dartcafe commented 3 years ago

Another solution might be to offer a method to resolve the RRULE and get the recurrences' datetimes.

dartcafe commented 2 years ago

Just for the record, also the implementation of OCP\Calendar\IManager::newQuery()->setTimerangeStart()->->setTimerangeEnd() has this issue.

Is there any chance this could get fixed in the near future?

dartcafe commented 2 years ago

@szaimen Any Chance to get this fixed on in the near future?

szaimen commented 2 years ago

Any Chance to get this fixed on in the near future?

Unfortunately, I don't know :/

szaimen commented 1 year ago

Hi, please update to 24.0.9 or better 25.0.3 and report back if it fixes the issue. Thank you!

My goal is to add a label like e.g. 25-feedback to this ticket of an up-to-date major Nextcloud version where the bug could be reproduced. However this is not going to work without your help. So thanks for all your effort!

If you don't manage to reproduce the issue in time and the issue gets closed but you can reproduce the issue afterwards, feel free to create a new bug report with up-to-date information by following this link: https://github.com/nextcloud/server/issues/new?assignees=&labels=bug%2C0.+Needs+triage&template=BUG_REPORT.yml&title=%5BBug%5D%3A+