python-caldav / caldav

Apache License 2.0
313 stars 91 forks source link

Exception dates for recurring events #373

Closed siderai closed 6 months ago

siderai commented 6 months ago

I have a trouble adding EXDATE field to recurring events. Currently, I am trying to convert caldav.Event to ics.Event, change the data, convent back to caldav.Event and then save. Not to mention that this solution is ugly, it's also unstable. I am looking for more native and convenient way. Any advice?

tobixen commented 6 months ago

The native way of doing the convertion is to use event.icalendar_component, so in this case it would be something like event.icalendar_component.add('EXDATE', my_exdate) (not tested).

I'm trying to avoid "silly convertions" in the library both for performance reasons and because it may change the data itself, but to be honest I've lost the overview of how often it's done in the library. I should do some research into this at some point. The way to do it without "silly convertions" goes something like this: event.data = event.data.replace("END:VEVENT", f"EXDATE:{my_exdate}\nEND:VEVENT"). Again, not tested at all.

I think convertion is probably a more robust solution than the replace solution.