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

fix recurrence exception handling #373

Merged
merged 3 commits into from Dec 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 28 additions & 14 deletions Helpers.gs
Expand Up @@ -187,10 +187,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 @@ -467,8 +478,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 @@ -629,16 +639,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