derekantrican / GAS-ICS-Sync

A Google Apps Script for syncing ICS/ICAL files faster than the current Google Calendar speed
GNU General Public License v3.0
1.5k stars 192 forks source link

Split up recurring event [Request] #439

Open vivimage opened 4 months ago

vivimage commented 4 months ago

Is your feature request related to a problem? Please describe.

No response

Describe the solution you'd like

Is it possible to sync recurring event not as a recurring event but split it up into individual events?

Additional context

No response

jonas0b1011001 commented 4 months ago

In theory yes. ical.js has a RecurExpansion class to provide the needed start dates.

vivimage commented 4 months ago

Thank you for an insight! Which part of the script will I need to change to add this? Will be grateful, if you can lead me

jonas0b1011001 commented 4 months ago

Try this: add

if (event.hasProperty('rrule')||event.hasProperty('rdate')){
    let icalEvent = new ICAL.Event(event, {strictExceptions: true});
    let dtstart = event.getFirstPropertyValue('dtstart');
    let recExpand = new ICAL.RecurExpansion({component: event, dtstart: dtstart});
    let duration = icalEvent.endDate.subtractDate(icalEvent.startDate);
    let uid = event.getFirstPropertyValue('uid').toString();
    let nextStart;
    event.removeProperty('rrule');
    event.removeProperty('rdate');
    event.removeProperty('exdate');
    let i = 0;
    while (i < 30 && (nextStart = recExpand.next())){
      event.updatePropertyWithValue('dtstart', nextStart);
      nextStart.addDuration(duration);
      event.updatePropertyWithValue('dtend', nextStart);
      event.updatePropertyWithValue('uid', uid + nextStart.toICALString());
      icsEventsIds.push('uid', uid + nextStart.toICALString());
      let component = new ICAL.Component.fromString(event.toString());
      processEvent(component, calendarTz);
      i++;
    }
    return;
  }

right above https://github.com/derekantrican/GAS-ICS-Sync/blob/3c36a55aaa61ac6abee037ba7a5e7d8334620b36/Helpers.gs#L291

vivimage commented 4 months ago

Thank you! It almost works, but sometimes duplicates an event. Weird that its not always happening. On some reoccurrence it's not happening. image

jonas0b1011001 commented 4 months ago

I can't reproduce that, have you done any other changes to the script? What settings are you using?

vivimage commented 4 months ago

Default settings, default script. Only with changes you provided. I delete the calendar and let the script create a calendar from scratch.

Seems like it's happening if one event in reccuring series is changed

jonas0b1011001 commented 4 months ago

Seems like it's happening if one event in reccuring series is changed

That makes sense, i'll look into it.

jonas0b1011001 commented 4 months ago

Give this version a try.

There have been changes in various places, i think it's easier to share the whole script than list all changes here.

vivimage commented 4 months ago

Thank you very much! Duplicating of events stopped.

I'm noticed one issue. Again only happening with edited events in reccuring series. Its not picking up the change in the timezones, when expanding.

I moved to another country and changed the Google calendar timezone. The expanded event (from edited event in recurring series) haven't picked up the change. So there is difference between original event time and expanded event time.

jonas0b1011001 commented 4 months ago

Again only happening with edited events in reccuring series.

Can you share a minimal *.ics you are testing this with? Google calendar for example 'discards' timezones of recurrence exceptions when exporting the calendar.

vivimage commented 4 months ago

https://calendar.google.com/calendar/ical/6c199906f611efbb417e414973337dd12e87e267e0e753c311b657703e67d030%40group.calendar.google.com/private-00638ada960c706c9eb7cd467a881913/basic.ics

I unfortunately deleted the event that was causing the issue.

vivimage commented 4 months ago

Any work around that Google discards timezones from recurrence exceptions?

jonas0b1011001 commented 4 months ago

Any work around that Google discards timezones from recurrence exceptions?

No, that's just the way google handles it.

Nevertheless the events should all be at the correct timeslot (albeit in a wrong timezone) in regards to the timezone set in your target calendar. Is that the case?

vivimage commented 4 months ago

I can't reproduce the issue that I was having yet. The events were appearing in different timeslots

vivimage commented 4 months ago

image

Started receiving this error on execution.

The .ics: https://calendar.google.com/calendar/ical/5777ff39396824cd7783b1699ebf40a794c091a7e842ea285efd8a4691c6903b%40group.calendar.google.com/private-cc298dcacf59effca281fea225bec509/basic.ics

jonas0b1011001 commented 4 months ago

https://script.google.com/d/1hme8yZDWgU6Gd4WQIszMS0agh0zkxTap7Um89XEBBkBIR6lbKGJ2fkWS/edit?usp=sharing

vivimage commented 4 months ago

In this version it's duplicating reccuring exception events with each execution

jonas0b1011001 commented 4 months ago

My bad, https://script.google.com/d/1hme8yZDWgU6Gd4WQIszMS0agh0zkxTap7Um89XEBBkBIR6lbKGJ2fkWS/edit?usp=sharing

vivimage commented 3 months ago

Still testing it. Works like a charm so far.

The only thing, that I'm noticing, as I understand from looking on a calendar, that for reccuring exception events it first create event in an original position (default time from reccuring event) and then moves to a proper time.

The problem, that I'm noticing, that sometimes it is stuck in an original position for a whole time of execution cycle. And with the next execution it moves itself to a proper place.

Don't really know what causing it. Is there a way to make sure event is not stuck in an original position?

Thank you very much!

jonas0b1011001 commented 3 months ago

Script from above is updated.