From b7496a5d6b5a4d39a1621903d5cc66679b519ea8 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Fri, 5 Aug 2016 14:53:38 -0400 Subject: [PATCH] (fix) correctly calculate recurrence exceptions --- SoObjects/Appointments/SOGoAppointmentFolder.m | 17 ++++++++++++----- SoObjects/Appointments/SOGoAppointmentObject.m | 14 +++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/SoObjects/Appointments/SOGoAppointmentFolder.m b/SoObjects/Appointments/SOGoAppointmentFolder.m index 17845a406..a6a1c3ffa 100644 --- a/SoObjects/Appointments/SOGoAppointmentFolder.m +++ b/SoObjects/Appointments/SOGoAppointmentFolder.m @@ -966,12 +966,16 @@ firstInstanceCalendarDateRange: (NGCalendarDateRange *) fir withTimeZone: (NSTimeZone *) tz toArray: (NSMutableArray *) ma { + NGCalendarDateRange *recurrenceIdRange; NSCalendarDate *recurrenceId; NSMutableDictionary *newRecord; NGCalendarDateRange *newRecordRange; NSComparisonResult compare; - int recordIndex, secondsOffsetFromGMT; NSNumber *dateSecs; + id master; + + int recordIndex, secondsOffsetFromGMT; + NSTimeInterval delta; newRecord = nil; recurrenceId = [component recurrenceId]; @@ -993,16 +997,19 @@ firstInstanceCalendarDateRange: (NGCalendarDateRange *) fir [recurrenceId setTimeZone: tz]; } - compare = [[dateRange startDate] compare: recurrenceId]; - if ((compare == NSOrderedAscending || compare == NSOrderedSame) && - [[dateRange endDate] compare: recurrenceId] == NSOrderedDescending) + master = [[[component parent] events] objectAtIndex: 0]; + delta = [[master endDate] timeIntervalSinceDate: [master startDate]]; + recurrenceIdRange = [NGCalendarDateRange calendarDateRangeWithStartDate: recurrenceId + endDate: [recurrenceId dateByAddingYears:0 months:0 days:0 hours:0 minutes:0 seconds: delta]]; + if ([dateRange doesIntersectWithDateRange: recurrenceIdRange]) { // The recurrence exception intersects with the date range; // find the occurence and replace it with the new record recordIndex = [self _indexOfRecordMatchingDate: recurrenceId inArray: ma]; if (recordIndex > -1) { - if ([dateRange containsDate: [component startDate]]) + if ([dateRange containsDate: [component startDate]] || + [dateRange containsDate: [component endDate]]) { // We must pass nil to :container here in order to avoid re-entrancy issues. newRecord = [self _fixupRecord: [component quickRecordFromContent: nil container: nil]]; diff --git a/SoObjects/Appointments/SOGoAppointmentObject.m b/SoObjects/Appointments/SOGoAppointmentObject.m index 43b895d8f..0a770a3f8 100644 --- a/SoObjects/Appointments/SOGoAppointmentObject.m +++ b/SoObjects/Appointments/SOGoAppointmentObject.m @@ -557,13 +557,9 @@ reason = [values keysWithFormat: [self labelForKey: @"Cannot access resource: \"%{Cn} %{SystemEmail}\""]]; return [NSException exceptionWithHTTPStatus:409 reason: reason]; } - + fbInfo = [NSMutableArray arrayWithArray: [folder fetchFreeBusyInfosFrom: start - to: end]]; - - // We first remove any occurences in the freebusy that corresponds to the - // current event. We do this to avoid raising a conflict if we move a 1 hour - // meeting from 12:00-13:00 to 12:15-13:15. We would overlap on ourself otherwise. + to: end]]; // // We must also check here for repetitive events that don't overlap our event. // We remove all events that don't overlap. The events here are already @@ -592,13 +588,14 @@ range = [NGCalendarDateRange calendarDateRangeWithStartDate: rangeStartDate endDate: rangeEndDate]; - // We remove the freebusy entries corresponding to the actual event being modified + // We first remove any occurences in the freebusy that corresponds to the + // current event. We do this to avoid raising a conflict if we move a 1 hour + // meeting from 12:00-13:00 to 12:15-13:15. We would overlap on ourself otherwise. if ([[[fbInfo objectAtIndex: i] objectForKey: @"c_uid"] compare: [theEvent uid]] == NSOrderedSame) { [fbInfo removeObjectAtIndex: i]; continue; } - // No need to check if the event isn't recurrent here as it's handled correctly // when we compute the "end" date. if ([allOccurences count]) @@ -613,7 +610,6 @@ break; } } - if (must_delete) [fbInfo removeObjectAtIndex: i]; }