Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calendar.search-method with timestamp filters yielding too much #351

Open
ArtemIsmagilov opened this issue Dec 1, 2023 · 8 comments
Open
Labels
Milestone

Comments

@ArtemIsmagilov
Copy link
Contributor

ArtemIsmagilov commented Dec 1, 2023

  • this code not correct return events.
  • start= 2023-12-01 00:00:00.793241+03:00
  • end= 2023-12-01 23:59:58.793241+03:00
start = datetime.now(ZoneInfo("Europe/Moscow")).replace(hour=0, minute=0, second=0)
end = start.replace(hour=23, minute=59, second=58)
print(start, end)
for e in c.search(comp_class=Event, start=start, end=end,  sort_keys=("DTSTART",)):
    if e.icalendar_component.get("X-TELEMOST-CONFERENCE"):
        print(Conference(e.icalendar_component, "Europe/Moscow"))

Result -

<Conference uid:'1o1h3lz1v41v9n4agilx3yandex.ru' timezone:Europe/Moscow dtstart:'2023-12-02T00:00:00+03:00' dtend:'2023-12-03T00:00:00+03:00'>

<Conference uid:'1o1h3lz1v37k5aqz0qnj5yandex.ru' timezone:Europe/Moscow dtstart:'2023-12-02T00:00:00+03:00' dtend:'2023-12-03T00:00:00+03:00'>

<Conference uid:'1o1h3lz1v42eaqesvjq18yandex.ru' timezone:Europe/Moscow dtstart:'2023-12-01T15:03:00+03:00' dtend:'2023-12-01T15:06:00+03:00'>

<Conference uid:'1o1h3lz1v32qqkecq84p7yandex.ru' timezone:Europe/Moscow dtstart:'2023-12-01T00:00:00+03:00' dtend:'2023-12-02T00:00:00+03:00'>

<Conference uid:'1o1h3lz1v37jb80pqkwz9yandex.ru' timezone:Europe/Moscow dtstart:'2023-12-01T00:00:00+03:00' dtend:'2023-12-02T00:00:00+03:00'>

<Conference uid:'1o1h3lz1v37jdou17koz4yandex.ru' timezone:Europe/Moscow dtstart:'2023-12-01T00:00:00+03:00' dtend:'2023-12-02T00:00:00+03:00'>

<Conference uid:'1o1h3lz1v37k6id2q50t0yandex.ru' timezone:Europe/Moscow dtstart:'2023-12-02T00:00:00+03:00' dtend:'2023-12-03T00:00:00+03:00'>

<Conference uid:'1o1h3lz1v399c37e8i7s0yandex.ru' timezone:Europe/Moscow dtstart:'2023-12-01T00:00:00+03:00' dtend:'2023-12-02T00:00:00+03:00'>

<Conference uid:'1o1h3lz1v41v8u0b3prp6yandex.ru' timezone:Europe/Moscow dtstart:'2023-12-01T00:00:00+03:00' dtend:'2023-12-02T00:00:00+03:00'>

<Conference uid:'1o1h3lz1v32qsp1riff59yandex.ru' timezone:Europe/Moscow dtstart:'2023-12-02T00:00:00+03:00' dtend:'2023-12-03T00:00:00+03:00'>

<Conference uid:'1o1h3lz1va12d54vfi7j4yandex.ru' timezone:Europe/Moscow dtstart:'2023-12-01T09:30:00+03:00' dtend:'2023-12-01T10:00:00+03:00'>

<Conference uid:'1o1h3lz1v39az2eqax4g7yandex.ru' timezone:Europe/Moscow dtstart:'2023-12-01T05:57:00+03:00' dtend:'2023-12-01T06:00:00+03:00'>

<Conference uid:'1o1h3lz1v42lol7oyhak1yandex.ru' timezone:Europe/Moscow dtstart:'2023-12-01T14:53:00+03:00' dtend:'2023-12-01T15:23:00+03:00'>

<Conference uid:'1o1h3lz1v42l92t9n91k8yandex.ru' timezone:Europe/Moscow dtstart:'2023-12-01T14:57:00+03:00' dtend:'2023-12-01T15:27:00+03:00'>

<Conference uid:'1o1h3lz1v421rx9uahkx9yandex.ru' timezone:Europe/Moscow dtstart:'2023-12-01T13:17:00+03:00' dtend:'2023-12-01T13:18:00+03:00'>

<Conference uid:'1o1h3lz1ux74blqchq460yandex.ru' timezone:Europe/Moscow dtstart:'2023-12-01T00:00:00+03:00' dtend:'2023-12-02T00:00:00+03:00'>

<Conference uid:'1o1h3lz1v399ejhoh4em9yandex.ru' timezone:Europe/Moscow dtstart:'2023-12-02T00:00:00+03:00' dtend:'2023-12-03T00:00:00+03:00'>

<Conference uid:'1o1h3lz1v43nqe7uk4jx6yandex.ru' timezone:Europe/Moscow dtstart:'2023-12-01T17:48:00+03:00' dtend:'2023-12-01T18:18:00+03:00' >

Problem - not sorted and wrong searching start and stop

@tobixen
Copy link
Member

tobixen commented Dec 1, 2023

Hm ... this is two issues indeed, problems with sorting and problems with the search. I will raise a separate issue for the sorting problem.

@tobixen tobixen changed the title wrong calendar.search method calendar.search-method with timestamp filters yielding too much Dec 1, 2023
@tobixen
Copy link
Member

tobixen commented Dec 1, 2023

So you have three events marked that starts midnight MSK 2nd of December and ends midnight MSK 3rd of December (are they really stored with timestamps rather than dates in the calendar? May I see the full icalendar code?). They should not be returned because the end of the search is set to 23:59:59 at the 1st of December (I don't think the caldav standard supports milliseconds in the search timestamps).

One possible reason could be that the search-code handles timezones wrongly. I don't think we have test code exercising timestamp search with timezones. Could you please try and see if it works out correctly when passing UTC timestamps? Something like this:

from datetime import timezone, datetime, timedelta
start = datetime(2023,12,1,0,0,0,tzinfo=timezone.utc)
end = start + timedelta(days=1)

Try with different values for start, midnight MSK is 21:00:00 UTC.

Does yandex offer caldav support? Is it possible to create a yandex account dedicated for running the caldav test suite?

@ArtemIsmagilov
Copy link
Contributor Author

ArtemIsmagilov commented Dec 1, 2023

Yandex calendar works using the CalDAV protocol. Your example did not change the result. Yes, you can create an account in Yandex Calendar.
Go to the Yandex ID website https://id.yandex.ru/
Log in or register
Go to Security
At the very bottom are the Application passwords
Click on the CalDAV Calendar and create a password
To integrate, you will need a Yandex account login and a previously created password

@ArtemIsmagilov
Copy link
Contributor Author

ArtemIsmagilov commented Dec 1, 2023

my code

import logging, caldav
from caldav import Event
from datetime import datetime, UTC
logging.basicConfig(level=logging.DEBUG)
login, token =  login, token 
with caldav.DAVClient(url=f'https://{login}:{token}@caldav.yandex.ru') as client:
    principal = client.principal()
    c = principal.calendar(cal_id=cal_id)
    start = datetime.now(ZoneInfo("Europe/Moscow")).replace(hour=0, minute=0, second=0)
    end = start.replace(hour=23, minute=59, second=59) 
    print(start, end)
    for e in c.search(comp_class=Event, start=start, end=end,  sort_keys=("DTSTART",)):
        if e.icalendar_component.get("X-TELEMOST-CONFERENCE"):
            print(Conference(e.icalendar_component, "Europe/Moscow"))

you can view full code in an open source project https://github.com/ArtemIsmagilov/mm-yc-notify

@tobixen
Copy link
Member

tobixen commented Dec 1, 2023

I will try to register my own yandex calendar and play with it, but I cannot tell when I will get time for that.

@tobixen
Copy link
Member

tobixen commented Dec 1, 2023

I should also make test code testing the search algorithm with various timezones and see if that may be an issue. Again, I cannot tell when I will get time for that.

@ArtemIsmagilov
Copy link
Contributor Author

What I learned is that freebusy is not supported in Yandex Calendar. Also, this calendar is constantly changing some event attributes, which is why the token changes even if you don’t change the events at all.

@tobixen
Copy link
Member

tobixen commented Jan 15, 2024

Unable to register account with yandex, it wants to confirm my telephone number, but the SMS doesn't get through :-(

@tobixen tobixen added the bug label Jan 15, 2024
@tobixen tobixen added this to the v.1.x milestone Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants