Skip to content

Commit

Permalink
fix recurrence exception handling (#373)
Browse files Browse the repository at this point in the history
* recurrence exception fix

attempt to fix recurrence issue from discord

* Respect modifyExistingEvents and addEventsToCalendar setting in processEventInstance()

* Skip of no tz is specified
  • Loading branch information
jonas0b1011001 authored Dec 13, 2023
1 parent 29b193d commit f88b3d0
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions Helpers.gs
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,21 @@ function parseResponses(responses){
event.updatePropertyWithValue('uid', Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, event.toString()).toString());
}
if(event.hasProperty('recurrence-id')){
var recID = new ICAL.Time.fromString(event.getFirstPropertyValue('recurrence-id').toString(), event.getFirstProperty('recurrence-id'));
var recUTC = recID.convertToZone(ICAL.TimezoneService.get('UTC')).toString();

icsEventsIds.push(event.getFirstPropertyValue('uid').toString() + "_" + recUTC);
let recID = new ICAL.Time.fromString(event.getFirstPropertyValue('recurrence-id').toString(), event.getFirstProperty('recurrence-id'));
if (event.getFirstProperty('recurrence-id').getParameter('tzid')){
let recUTCOffset = 0;
let tz = event.getFirstProperty('recurrence-id').getParameter('tzid').toString();
if (tz in tzidreplace){
tz = tzidreplace[tz];
}
let jsTime = new Date();
let utcTime = new Date(Utilities.formatDate(jsTime, "Etc/GMT", "HH:mm:ss MM/dd/yyyy"));
let tgtTime = new Date(Utilities.formatDate(jsTime, tz, "HH:mm:ss MM/dd/yyyy"));
recUTCOffset = (tgtTime - utcTime)/-1000;
recID = recID.adjust(0,0,0,recUTCOffset).toString() + "Z";
event.updatePropertyWithValue('recurrence-id', recID);
}
icsEventsIds.push(event.getFirstPropertyValue('uid').toString() + "_" + recID);
}
else{
icsEventsIds.push(event.getFirstPropertyValue('uid').toString());
Expand Down Expand Up @@ -480,8 +491,7 @@ function createEvent(event, calendarTz){
newEvent.extendedProperties = { private: { MD5 : digest, fromGAS : "true", id : icalEvent.uid } };

if (event.hasProperty('recurrence-id')){
var recID = new ICAL.Time.fromString(event.getFirstPropertyValue('recurrence-id').toString(), event.getFirstProperty('recurrence-id'));
newEvent.recurringEventId = recID.convertToZone(ICAL.TimezoneService.get('UTC')).toString();
newEvent.recurringEventId = event.getFirstPropertyValue('recurrence-id').toString();
newEvent.extendedProperties.private['rec-id'] = newEvent.extendedProperties.private['id'] + "_" + newEvent.recurringEventId;
}

Expand Down Expand Up @@ -656,16 +666,20 @@ function processEventInstance(recEvent){
}

if (eventInstanceToPatch !== null && eventInstanceToPatch.length == 1){
Logger.log("Updating existing event instance");
callWithBackoff(function(){
Calendar.Events.update(recEvent, targetCalendarId, eventInstanceToPatch[0].id);
}, defaultMaxRetries);
if (modifyExistingEvents){
Logger.log("Updating existing event instance");
callWithBackoff(function(){
Calendar.Events.update(recEvent, targetCalendarId, eventInstanceToPatch[0].id);
}, defaultMaxRetries);
}
}
else{
Logger.log("No Instance matched, adding as new event!");
callWithBackoff(function(){
Calendar.Events.insert(recEvent, targetCalendarId);
}, defaultMaxRetries);
if (addEventsToCalendar){
Logger.log("No Instance matched, adding as new event!");
callWithBackoff(function(){
Calendar.Events.insert(recEvent, targetCalendarId);
}, defaultMaxRetries);
}
}
}

Expand Down

0 comments on commit f88b3d0

Please sign in to comment.