mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-05-23 12:25:23 +00:00
Fix handling of weekly recurrence rule with count
This fixes some corner cases when computing the freebusy and therefore when verifying for resource conflicts.
This commit is contained in:
@@ -97,6 +97,7 @@ extern NSString *iCalWeekDayString[];
|
||||
|
||||
/* count and untilDate are mutually exclusive */
|
||||
|
||||
- (BOOL) hasRepeatCount;
|
||||
- (void) setRepeatCount: (int) _repeatCount;
|
||||
- (int) repeatCount;
|
||||
|
||||
|
||||
@@ -403,6 +403,11 @@ NSString *iCalWeekDayString[] = { @"SU", @"MO", @"TU", @"WE", @"TH", @"FR",
|
||||
return [[self flattenedValuesForKey: @"count"] intValue];
|
||||
}
|
||||
|
||||
- (BOOL) hasRepeatCount
|
||||
{
|
||||
return [[self flattenedValuesForKey: @"count"] length] > 0;
|
||||
}
|
||||
|
||||
- (void) setCount: (NSString *) _count
|
||||
{
|
||||
[self setSingleValue: _count forKey: @"count"];
|
||||
|
||||
@@ -68,6 +68,7 @@
|
||||
long i, repeatCount, count;
|
||||
unsigned interval;
|
||||
iCalByDayMask *dayMask;
|
||||
BOOL hasRepeatCount;
|
||||
|
||||
[self logWithFormat: @"Weekly %@", rrule];
|
||||
|
||||
@@ -76,6 +77,7 @@
|
||||
endDate = [_r endDate];
|
||||
dayMask = nil;
|
||||
repeatCount = 0;
|
||||
hasRepeatCount = [rrule hasRepeatCount];
|
||||
|
||||
if ([endDate compare: firStart] == NSOrderedAscending)
|
||||
// Range ends before first occurrence
|
||||
@@ -113,7 +115,7 @@
|
||||
return nil;
|
||||
if ([lastDate compare: endDate] == NSOrderedAscending)
|
||||
// Range ends after last occurence; adjust end date
|
||||
endDate = lastDate;
|
||||
endDate = [lastDate addTimeInterval: [firstRange duration]];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,9 +131,7 @@
|
||||
[currentStartDate compare: endDate] == NSOrderedSame)
|
||||
{
|
||||
currentEndDate = [currentStartDate addTimeInterval: [firstRange duration]];
|
||||
if ([startDate compare: currentStartDate] == NSOrderedAscending ||
|
||||
[startDate compare: currentStartDate] == NSOrderedSame ||
|
||||
[startDate compare: currentEndDate] == NSOrderedAscending)
|
||||
if ([startDate compare: currentEndDate] == NSOrderedAscending)
|
||||
{
|
||||
NGCalendarDateRange *r;
|
||||
|
||||
@@ -156,9 +156,9 @@
|
||||
BOOL isRecurrence = NO;
|
||||
NSInteger week;
|
||||
|
||||
if (repeatCount > 0 ||
|
||||
[startDate compare: currentStartDate] == NSOrderedAscending ||
|
||||
[startDate compare: currentStartDate] == NSOrderedSame)
|
||||
currentEndDate = [currentStartDate addTimeInterval: [firstRange duration]];
|
||||
if (hasRepeatCount ||
|
||||
[startDate compare: currentEndDate] == NSOrderedAscending)
|
||||
{
|
||||
// If the rule count is defined, stop once the count is reached.
|
||||
if ([currentStartDate compare: firStart] == NSOrderedSame)
|
||||
@@ -181,10 +181,8 @@
|
||||
count++;
|
||||
if (repeatCount > 0 && count > repeatCount)
|
||||
break;
|
||||
currentEndDate = [currentStartDate addTimeInterval: [firstRange duration]];
|
||||
r = [NGCalendarDateRange calendarDateRangeWithStartDate: currentStartDate
|
||||
endDate: currentEndDate];
|
||||
|
||||
if ([_r doesIntersectWithDateRange: r])
|
||||
{
|
||||
[ranges addObject: r];
|
||||
|
||||
@@ -177,15 +177,15 @@
|
||||
NSCalendarDate *date;
|
||||
|
||||
date = [self lastPossibleRecurrenceStartDate];
|
||||
if (!date)
|
||||
{
|
||||
/* this could also be *nil*, but in the end it makes the fetchspecs
|
||||
more complex - thus we set it to a "reasonable" distant future */
|
||||
date = iCalDistantFuture;
|
||||
}
|
||||
if (date)
|
||||
date = [date addTimeInterval: [self durationAsTimeInterval]];
|
||||
else
|
||||
/* this could also be *nil*, but in the end it makes the fetchspecs
|
||||
more complex - thus we set it to a "reasonable" distant future */
|
||||
date = iCalDistantFuture;
|
||||
[row setObject: [self quickRecordDateAsNumber: date
|
||||
withOffset: 0 forAllDay: NO]
|
||||
forKey: @"c_cycleenddate"];
|
||||
withOffset: 0 forAllDay: NO]
|
||||
forKey: @"c_cycleenddate"];
|
||||
[row setObject: [self cycleInfo] forKey: @"c_cycleinfo"];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user