(fix) correctly calculate recurrence exceptions

pull/27/merge
Ludovic Marcotte 2016-08-05 14:53:38 -04:00
parent d2b20c88c3
commit b7496a5d6b
2 changed files with 17 additions and 14 deletions

View File

@ -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]];

View File

@ -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];
}