From dd6f8ef810509c34a91a9e30d903baf97136496a Mon Sep 17 00:00:00 2001 From: znek Date: Tue, 15 Feb 2005 17:03:55 +0000 Subject: [PATCH] additions git-svn-id: http://svn.opengroupware.org/SOPE/trunk@562 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-ical/NGiCal/ChangeLog | 11 +++ sope-ical/NGiCal/NGiCal.xcode/project.pbxproj | 4 +- sope-ical/NGiCal/Version | 2 +- sope-ical/NGiCal/iCalEvent.h | 2 + sope-ical/NGiCal/iCalEvent.m | 12 ++++ sope-ical/NGiCal/iCalRepeatableEntityObject.h | 2 + sope-ical/NGiCal/iCalRepeatableEntityObject.m | 68 ++++++++++++------- 7 files changed, 72 insertions(+), 29 deletions(-) diff --git a/sope-ical/NGiCal/ChangeLog b/sope-ical/NGiCal/ChangeLog index e3febed9..45fe292c 100644 --- a/sope-ical/NGiCal/ChangeLog +++ b/sope-ical/NGiCal/ChangeLog @@ -1,3 +1,14 @@ +2005-02-15 Marcus Mueller + + * v4.5.42 + + * iCalRepeatableEntityObject.[hm]: added ability to properly calculate + the recurrence ranges within a specific calendar date range, taking + all possible exceptions into account. + + * iCalEvent.[hm]: convenience wrapper for the new method found in + iCalRepeatableEntityObject. + 2005-02-14 Helge Hess * v4.5.41 diff --git a/sope-ical/NGiCal/NGiCal.xcode/project.pbxproj b/sope-ical/NGiCal/NGiCal.xcode/project.pbxproj index 33a59f72..f7365484 100644 --- a/sope-ical/NGiCal/NGiCal.xcode/project.pbxproj +++ b/sope-ical/NGiCal/NGiCal.xcode/project.pbxproj @@ -164,7 +164,7 @@ ); buildSettings = { DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 4.5.40; + DYLIB_CURRENT_VERSION = 4.5.42; FRAMEWORK_SEARCH_PATHS = "\"$(USER_LIBRARY_DIR)/EmbeddedFrameworks\""; FRAMEWORK_VERSION = A; GCC_PRECOMPILE_PREFIX_HEADER = NO; @@ -578,7 +578,7 @@ ); buildSettings = { DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 4.5.40; + DYLIB_CURRENT_VERSION = 4.5.42; FRAMEWORK_SEARCH_PATHS = "$(LOCAL_LIBRARY_DIR)/Frameworks"; FRAMEWORK_VERSION = A; GCC_PRECOMPILE_PREFIX_HEADER = YES; diff --git a/sope-ical/NGiCal/Version b/sope-ical/NGiCal/Version index 50a3ce02..03d46ce9 100644 --- a/sope-ical/NGiCal/Version +++ b/sope-ical/NGiCal/Version @@ -2,7 +2,7 @@ MAJOR_VERSION=4 MINOR_VERSION=5 -SUBMINOR_VERSION:=41 +SUBMINOR_VERSION:=42 # v4.5.40 requires NGExtensions v4.5.145 # v4.5.37 requires NGExtensions v4.5.140 diff --git a/sope-ical/NGiCal/iCalEvent.h b/sope-ical/NGiCal/iCalEvent.h index 59c2602a..9e07b2c5 100644 --- a/sope-ical/NGiCal/iCalEvent.h +++ b/sope-ical/NGiCal/iCalEvent.h @@ -62,6 +62,8 @@ - (BOOL)isAllDay; - (BOOL)isWithinCalendarDateRange:(NGCalendarDateRange *)_range; +- (NSArray *)recurrenceRangesWithinCalendarDateRange:(NGCalendarDateRange *)_r; + - (NSCalendarDate *)lastPossibleRecurrenceStartDate; /* calculating changes */ diff --git a/sope-ical/NGiCal/iCalEvent.m b/sope-ical/NGiCal/iCalEvent.m index 34217f02..a0b71d5f 100644 --- a/sope-ical/NGiCal/iCalEvent.m +++ b/sope-ical/NGiCal/iCalEvent.m @@ -170,6 +170,18 @@ return NO; } +- (NSArray *)recurrenceRangesWithinCalendarDateRange:(NGCalendarDateRange *)_r { + NGCalendarDateRange *fir; + + if (![self isRecurrent]) + return nil; + + fir = [NGCalendarDateRange calendarDateRangeWithStartDate:self->startDate + endDate:self->endDate]; + return [self recurrenceRangesWithinCalendarDateRange:_r + firstInstanceCalendarDateRange:fir]; +} + - (NSCalendarDate *)lastPossibleRecurrenceStartDate { NGCalendarDateRange *fir; diff --git a/sope-ical/NGiCal/iCalRepeatableEntityObject.h b/sope-ical/NGiCal/iCalRepeatableEntityObject.h index 7fb90d6d..a57c01a6 100644 --- a/sope-ical/NGiCal/iCalRepeatableEntityObject.h +++ b/sope-ical/NGiCal/iCalRepeatableEntityObject.h @@ -58,6 +58,8 @@ - (BOOL)isRecurrent; - (BOOL)isWithinCalendarDateRange:(NGCalendarDateRange *)_range firstInstanceCalendarDateRange:(NGCalendarDateRange *)_fir; +- (NSArray *)recurrenceRangesWithinCalendarDateRange:(NGCalendarDateRange *)_r + firstInstanceCalendarDateRange:(NGCalendarDateRange *)_fir; /* this is the outmost bound possible, not necessarily the real last date */ - (NSCalendarDate *)lastPossibleRecurrenceStartDateUsingFirstInstanceCalendarDateRange:(NGCalendarDateRange *)_r; diff --git a/sope-ical/NGiCal/iCalRepeatableEntityObject.m b/sope-ical/NGiCal/iCalRepeatableEntityObject.m index 01242e3f..00f9fae7 100644 --- a/sope-ical/NGiCal/iCalRepeatableEntityObject.m +++ b/sope-ical/NGiCal/iCalRepeatableEntityObject.m @@ -107,58 +107,74 @@ /* Matching */ -/* ZNeK: NOTE - Exception dates give me a headache. I believe the test below is improper, - we probably really need to calculate all recurrence ranges and then - test whether exception dates are contained in any of the required ranges - and remove those which were found. -*/ - (BOOL)isWithinCalendarDateRange:(NGCalendarDateRange *)_range firstInstanceCalendarDateRange:(NGCalendarDateRange *)_fir +{ + NSArray *ranges; + + ranges = [self recurrenceRangesWithinCalendarDateRange:_range + firstInstanceCalendarDateRange:_fir]; + return [ranges count] > 0; +} + +- (NSArray *)recurrenceRangesWithinCalendarDateRange:(NGCalendarDateRange *)_r + firstInstanceCalendarDateRange:(NGCalendarDateRange *)_fir { iCalRecurrenceRule *rule; iCalRecurrenceCalculator *calc; - BOOL didMatch = NO; - unsigned i, count; + NSMutableArray *ranges; + unsigned i, count, rCount; - count = [self->rRules count]; + ranges = [NSMutableArray array]; + count = [self->rRules count]; for (i = 0; i < count; i++) { + NSArray *rs; + rule = [self->rRules objectAtIndex:i]; calc = [iCalRecurrenceCalculator recurrenceCalculatorForRecurrenceRule:rule withFirstInstanceCalendarDateRange:_fir]; - if ([calc doesRecurrWithinCalendarDateRange:_range]) { - didMatch = YES; - break; - } + rs = [calc recurrenceRangesWithinCalendarDateRange:_r]; + [ranges addObjectsFromArray:rs]; } - if (!didMatch) - return NO; - + if (![ranges count]) + return nil; + /* test if any exceptions do match */ count = [self->exRules count]; for (i = 0; i < count; i++) { - + NSArray *rs; + rule = [self->exRules objectAtIndex:i]; calc = [iCalRecurrenceCalculator recurrenceCalculatorForRecurrenceRule:rule withFirstInstanceCalendarDateRange:_fir]; - if ([calc doesRecurrWithinCalendarDateRange:_range]) - return NO; /* exception does match, so _range is not a candidate */ + rs = [calc recurrenceRangesWithinCalendarDateRange:_r]; + [ranges removeObjectsInArray:rs]; } + if (![ranges count]) + return nil; + /* exception dates are also possible */ - count = [self->exDates count]; + rCount = [ranges count]; + count = [self->exDates count]; for (i = 0; i < count; i++) { - NSCalendarDate *exDate; - + NSCalendarDate *exDate; + NGCalendarDateRange *r; + unsigned k; + exDate = [self->exDates objectAtIndex:i]; - /* ZNeK: is _this_ correct? */ - if ([exDate isEqualToDate:[_range startDate]]) - return NO; + for (k = 0; k < rCount; k++) { + r = [ranges objectAtIndex:(rCount - k) - 1]; + if ([r containsDate:exDate]) { + [ranges removeObjectAtIndex:k]; + } + } } - return YES; + return ranges; } + /* this is the outmost bound possible, not necessarily the real last date */ - (NSCalendarDate *)lastPossibleRecurrenceStartDateUsingFirstInstanceCalendarDateRange:(NGCalendarDateRange *)_r { -- 2.39.5