diff --git a/SOPE/NGCards/iCalRecurrenceRule.h b/SOPE/NGCards/iCalRecurrenceRule.h index dc5088930..4a14fa446 100644 --- a/SOPE/NGCards/iCalRecurrenceRule.h +++ b/SOPE/NGCards/iCalRecurrenceRule.h @@ -96,6 +96,7 @@ extern NSString *iCalWeekDayString[]; /* count and untilDate are mutually exclusive */ +- (BOOL) hasRepeatCount; - (void) setRepeatCount: (int) _repeatCount; - (int) repeatCount; diff --git a/SOPE/NGCards/iCalRecurrenceRule.m b/SOPE/NGCards/iCalRecurrenceRule.m index dc9ed28fa..7c581cbbf 100644 --- a/SOPE/NGCards/iCalRecurrenceRule.m +++ b/SOPE/NGCards/iCalRecurrenceRule.m @@ -409,6 +409,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"]; diff --git a/SOPE/NGCards/iCalWeeklyRecurrenceCalculator.m b/SOPE/NGCards/iCalWeeklyRecurrenceCalculator.m index 35b2e04b6..929fa5026 100644 --- a/SOPE/NGCards/iCalWeeklyRecurrenceCalculator.m +++ b/SOPE/NGCards/iCalWeeklyRecurrenceCalculator.m @@ -69,6 +69,7 @@ long i, repeatCount, count; unsigned interval; iCalByDayMask *dayMask; + BOOL hasRepeatCount; [self logWithFormat: @"Weekly %@", rrule]; @@ -77,6 +78,7 @@ endDate = [_r endDate]; dayMask = nil; repeatCount = 0; + hasRepeatCount = [rrule hasRepeatCount]; if ([endDate compare: firStart] == NSOrderedAscending) // Range ends before first occurrence @@ -114,7 +116,7 @@ return nil; if ([lastDate compare: endDate] == NSOrderedAscending) // Range ends after last occurence; adjust end date - endDate = lastDate; + endDate = [lastDate addTimeInterval: [firstRange duration]]; } } @@ -130,9 +132,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; @@ -157,9 +157,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) @@ -182,10 +182,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]; diff --git a/SoObjects/Appointments/iCalEvent+SOGo.m b/SoObjects/Appointments/iCalEvent+SOGo.m index 7948f7c23..ea3ca8276 100644 --- a/SoObjects/Appointments/iCalEvent+SOGo.m +++ b/SoObjects/Appointments/iCalEvent+SOGo.m @@ -174,15 +174,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"]; }