Fix handling of weekly recurrence rule with count
This fixes some corner cases when computing the freebusy and therefore when verifying for resource conflicts.pull/230/head
parent
892db449e5
commit
e948b45899
|
@ -96,6 +96,7 @@ extern NSString *iCalWeekDayString[];
|
||||||
|
|
||||||
/* count and untilDate are mutually exclusive */
|
/* count and untilDate are mutually exclusive */
|
||||||
|
|
||||||
|
- (BOOL) hasRepeatCount;
|
||||||
- (void) setRepeatCount: (int) _repeatCount;
|
- (void) setRepeatCount: (int) _repeatCount;
|
||||||
- (int) repeatCount;
|
- (int) repeatCount;
|
||||||
|
|
||||||
|
|
|
@ -409,6 +409,11 @@ NSString *iCalWeekDayString[] = { @"SU", @"MO", @"TU", @"WE", @"TH", @"FR",
|
||||||
return [[self flattenedValuesForKey: @"count"] intValue];
|
return [[self flattenedValuesForKey: @"count"] intValue];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL) hasRepeatCount
|
||||||
|
{
|
||||||
|
return [[self flattenedValuesForKey: @"count"] length] > 0;
|
||||||
|
}
|
||||||
|
|
||||||
- (void) setCount: (NSString *) _count
|
- (void) setCount: (NSString *) _count
|
||||||
{
|
{
|
||||||
[self setSingleValue: _count forKey: @"count"];
|
[self setSingleValue: _count forKey: @"count"];
|
||||||
|
|
|
@ -69,6 +69,7 @@
|
||||||
long i, repeatCount, count;
|
long i, repeatCount, count;
|
||||||
unsigned interval;
|
unsigned interval;
|
||||||
iCalByDayMask *dayMask;
|
iCalByDayMask *dayMask;
|
||||||
|
BOOL hasRepeatCount;
|
||||||
|
|
||||||
[self logWithFormat: @"Weekly %@", rrule];
|
[self logWithFormat: @"Weekly %@", rrule];
|
||||||
|
|
||||||
|
@ -77,6 +78,7 @@
|
||||||
endDate = [_r endDate];
|
endDate = [_r endDate];
|
||||||
dayMask = nil;
|
dayMask = nil;
|
||||||
repeatCount = 0;
|
repeatCount = 0;
|
||||||
|
hasRepeatCount = [rrule hasRepeatCount];
|
||||||
|
|
||||||
if ([endDate compare: firStart] == NSOrderedAscending)
|
if ([endDate compare: firStart] == NSOrderedAscending)
|
||||||
// Range ends before first occurrence
|
// Range ends before first occurrence
|
||||||
|
@ -114,7 +116,7 @@
|
||||||
return nil;
|
return nil;
|
||||||
if ([lastDate compare: endDate] == NSOrderedAscending)
|
if ([lastDate compare: endDate] == NSOrderedAscending)
|
||||||
// Range ends after last occurence; adjust end date
|
// Range ends after last occurence; adjust end date
|
||||||
endDate = lastDate;
|
endDate = [lastDate addTimeInterval: [firstRange duration]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,9 +132,7 @@
|
||||||
[currentStartDate compare: endDate] == NSOrderedSame)
|
[currentStartDate compare: endDate] == NSOrderedSame)
|
||||||
{
|
{
|
||||||
currentEndDate = [currentStartDate addTimeInterval: [firstRange duration]];
|
currentEndDate = [currentStartDate addTimeInterval: [firstRange duration]];
|
||||||
if ([startDate compare: currentStartDate] == NSOrderedAscending ||
|
if ([startDate compare: currentEndDate] == NSOrderedAscending)
|
||||||
[startDate compare: currentStartDate] == NSOrderedSame ||
|
|
||||||
[startDate compare: currentEndDate] == NSOrderedAscending)
|
|
||||||
{
|
{
|
||||||
NGCalendarDateRange *r;
|
NGCalendarDateRange *r;
|
||||||
|
|
||||||
|
@ -157,9 +157,9 @@
|
||||||
BOOL isRecurrence = NO;
|
BOOL isRecurrence = NO;
|
||||||
NSInteger week;
|
NSInteger week;
|
||||||
|
|
||||||
if (repeatCount > 0 ||
|
currentEndDate = [currentStartDate addTimeInterval: [firstRange duration]];
|
||||||
[startDate compare: currentStartDate] == NSOrderedAscending ||
|
if (hasRepeatCount ||
|
||||||
[startDate compare: currentStartDate] == NSOrderedSame)
|
[startDate compare: currentEndDate] == NSOrderedAscending)
|
||||||
{
|
{
|
||||||
// If the rule count is defined, stop once the count is reached.
|
// If the rule count is defined, stop once the count is reached.
|
||||||
if ([currentStartDate compare: firStart] == NSOrderedSame)
|
if ([currentStartDate compare: firStart] == NSOrderedSame)
|
||||||
|
@ -182,10 +182,8 @@
|
||||||
count++;
|
count++;
|
||||||
if (repeatCount > 0 && count > repeatCount)
|
if (repeatCount > 0 && count > repeatCount)
|
||||||
break;
|
break;
|
||||||
currentEndDate = [currentStartDate addTimeInterval: [firstRange duration]];
|
|
||||||
r = [NGCalendarDateRange calendarDateRangeWithStartDate: currentStartDate
|
r = [NGCalendarDateRange calendarDateRangeWithStartDate: currentStartDate
|
||||||
endDate: currentEndDate];
|
endDate: currentEndDate];
|
||||||
|
|
||||||
if ([_r doesIntersectWithDateRange: r])
|
if ([_r doesIntersectWithDateRange: r])
|
||||||
{
|
{
|
||||||
[ranges addObject: r];
|
[ranges addObject: r];
|
||||||
|
|
|
@ -174,15 +174,15 @@
|
||||||
NSCalendarDate *date;
|
NSCalendarDate *date;
|
||||||
|
|
||||||
date = [self lastPossibleRecurrenceStartDate];
|
date = [self lastPossibleRecurrenceStartDate];
|
||||||
if (!date)
|
if (date)
|
||||||
{
|
date = [date addTimeInterval: [self durationAsTimeInterval]];
|
||||||
/* this could also be *nil*, but in the end it makes the fetchspecs
|
else
|
||||||
more complex - thus we set it to a "reasonable" distant future */
|
/* this could also be *nil*, but in the end it makes the fetchspecs
|
||||||
date = iCalDistantFuture;
|
more complex - thus we set it to a "reasonable" distant future */
|
||||||
}
|
date = iCalDistantFuture;
|
||||||
[row setObject: [self quickRecordDateAsNumber: date
|
[row setObject: [self quickRecordDateAsNumber: date
|
||||||
withOffset: 0 forAllDay: NO]
|
withOffset: 0 forAllDay: NO]
|
||||||
forKey: @"c_cycleenddate"];
|
forKey: @"c_cycleenddate"];
|
||||||
[row setObject: [self cycleInfo] forKey: @"c_cycleinfo"];
|
[row setObject: [self cycleInfo] forKey: @"c_cycleinfo"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue