From 01177c1b659f47110a46581424c76fa27aca8517 Mon Sep 17 00:00:00 2001 From: znek Date: Mon, 14 Feb 2005 12:22:17 +0000 Subject: [PATCH] determine 'enddate' correctly for recurrent events, otherwise these wouldn't get fetched properly. git-svn-id: http://svn.opengroupware.org/SOGo/trunk@555 d1b88da0-ebda-0310-925b-ed51d893ca5b --- OGoContentStore/ChangeLog | 6 +++ OGoContentStore/OCSiCalFieldExtractor.m | 53 +++++++++++++++++-------- OGoContentStore/Version | 3 +- 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/OGoContentStore/ChangeLog b/OGoContentStore/ChangeLog index e70e89c5..ff081cfe 100644 --- a/OGoContentStore/ChangeLog +++ b/OGoContentStore/ChangeLog @@ -1,3 +1,9 @@ +2005-02-12 Marcus Mueller + + * OCSiCalFieldExtractor.m: uses new iCalEvent API to determine correct + 'enddate' for recurrent events. This is an optimization which can + save quite some time for complex rules. (v0.9.19) + 2004-12-17 Marcus Mueller * v0.9.18 diff --git a/OGoContentStore/OCSiCalFieldExtractor.m b/OGoContentStore/OCSiCalFieldExtractor.m index 6afdac26..cefa04ba 100644 --- a/OGoContentStore/OCSiCalFieldExtractor.m +++ b/OGoContentStore/OCSiCalFieldExtractor.m @@ -26,26 +26,32 @@ @implementation OCSiCalFieldExtractor -static id parser = nil; -static SaxObjectDecoder *sax = nil; -static OCSiCalFieldExtractor *extractor = nil; +static id parser = nil; +static SaxObjectDecoder *sax = nil; +static OCSiCalFieldExtractor *extractor = nil; +static NSCalendarDate *distantFuture = nil; +static NSNumber *distantFutureNumber = nil; + (void)initialize { - if (parser == nil) { - parser = [[[SaxXMLReaderFactory standardXMLReaderFactory] + static BOOL didInit = NO; + + if (didInit) return; + didInit = YES; + + parser = [[[SaxXMLReaderFactory standardXMLReaderFactory] createXMLReaderForMimeType:@"text/calendar"] retain]; - if (parser == nil) - NSLog(@"ERROR: did not find a parser for text/calendar!"); - } - if (sax == nil) { - sax = [[SaxObjectDecoder alloc] initWithMappingNamed:@"NGiCal"]; - if (sax == nil) + if (parser == nil) + NSLog(@"ERROR: did not find a parser for text/calendar!"); + sax = [[SaxObjectDecoder alloc] initWithMappingNamed:@"NGiCal"]; + if (sax == nil) NSLog(@"ERROR: could not create the iCal SAX handler!"); - } - [parser setContentHandler:sax]; [parser setErrorHandler:sax]; + + distantFuture = [[NSCalendarDate distantFuture] retain]; + /* INT_MAX due to Postgres constraint */ + distantFutureNumber = [[NSNumber numberWithUnsignedInt:INT_MAX] retain]; } + (id)sharedICalFieldExtractor { @@ -60,6 +66,8 @@ static OCSiCalFieldExtractor *extractor = nil; /* operations */ - (NSNumber *)numberForDate:(NSCalendarDate *)_date { + if (_date == distantFuture) + return distantFutureNumber; return [NSNumber numberWithUnsignedInt:[_date timeIntervalSince1970]]; } @@ -116,9 +124,22 @@ static OCSiCalFieldExtractor *extractor = nil; if ([startDate isNotNull]) [row setObject:[self numberForDate:startDate] forKey:@"startdate"]; - if ([endDate isNotNull]) - [row setObject:[self numberForDate:endDate] forKey:@"enddate"]; - + if (![_event isRecurrent]) { + if ([endDate isNotNull]) + [row setObject:[self numberForDate:endDate] forKey:@"enddate"]; + } + else { + NSCalendarDate *date; + + date = [_event lastPossibleRecurrenceStartDate]; + if (!date) { + /* date might be nil, indicating an unbound recurrence - we substitute + this with a very distant date since 'enddate' is not allowed to be + NULL */ + date = distantFuture; + } + [row setObject:[self numberForDate:date] forKey:@"enddate"]; + } if ([participants length] > 0) [row setObject:participants forKey:@"participants"]; if ([partmails length] > 0) diff --git a/OGoContentStore/Version b/OGoContentStore/Version index 1adba52a..ad8d9fe8 100644 --- a/OGoContentStore/Version +++ b/OGoContentStore/Version @@ -2,8 +2,9 @@ MAJOR_VERSION=0 MINOR_VERSION=9 -SUBMINOR_VERSION:=18 +SUBMINOR_VERSION:=19 +# v0.9.19 requires libNGiCal v4.5.40 # v0.9.18 requires libNGiCal v4.5.38 # v0.9.17 requires libNGiCal v4.5.37 # v0.9.11 requires libFoundation v1.0.63 -- 2.39.5