icalendar / icalendar-recurrence

Easy recurrence expansion for iCalendar
MIT License
41 stars 27 forks source link

UID for occurences #38

Closed guillaumebriday closed 1 month ago

guillaumebriday commented 2 months ago

I'm developing a calendar import system for my app and aim to import all occurrences of an event. I'm avoiding checking the start_time and end_time to prevent creating events when only the dates have changed in their calendar.

To prevent duplication, I've been using the event.uid, but it only exists on the event itself and not on individual occurrences, making it ineffective.

Do you have any suggestions on how to import occurrences without duplication?

Here is an extract of my code:

events.each_with_index do |event, index|
  event.occurrences_between(min_date, Time.current.end_of_day).each do |occurrence|
    TimeEntry
      .where(
        ical_uid: event.uid.to_s,
        user: calendar_sync.user,
        team: calendar_sync.team,
        calendar_sync: calendar_sync,
      )
      .first_or_create(
        description: event.summary.presence,
        start_at: occurrence.start_time,
        end_at: occurrence.end_time
      )
  end
end
rahearn commented 1 month ago

I'm not sure there is a good way to do that other than supporting the idea of repeating events rather than importing individual occurrences.