diff --git a/SOPE/NGCards/ChangeLog b/SOPE/NGCards/ChangeLog index 28740b538..00e9c352b 100644 --- a/SOPE/NGCards/ChangeLog +++ b/SOPE/NGCards/ChangeLog @@ -1,3 +1,9 @@ +2012-05-30 Francis Lachapelle + + * iCalRepeatableEntityObject.m (-exceptionDatesWithTimeZone:) + (-rules:withTimeZone:): exception dates and exception rules must + also be adjusted for floating all-day repeating events. + 2012-05-29 Francis Lachapelle * iCalRecurrenceCalculator.m diff --git a/SOPE/NGCards/iCalRecurrenceCalculator.m b/SOPE/NGCards/iCalRecurrenceCalculator.m index 7e60c0d9a..eebaa6dfb 100644 --- a/SOPE/NGCards/iCalRecurrenceCalculator.m +++ b/SOPE/NGCards/iCalRecurrenceCalculator.m @@ -201,7 +201,9 @@ static Class yearlyCalcClass = Nil; compare = [[currentRange startDate] compare: currentDate]; if ((compare == NSOrderedAscending || compare == NSOrderedSame) && [[currentRange endDate] compare: currentDate] == NSOrderedDescending) - [ranges removeObjectAtIndex: count - 1]; + { + [ranges removeObjectAtIndex: count - 1]; + } } } } diff --git a/SOPE/NGCards/iCalRepeatableEntityObject.h b/SOPE/NGCards/iCalRepeatableEntityObject.h index 9f70e2033..e1f259d4e 100644 --- a/SOPE/NGCards/iCalRepeatableEntityObject.h +++ b/SOPE/NGCards/iCalRepeatableEntityObject.h @@ -42,21 +42,21 @@ - (void)setRecurrenceRules:(NSArray *)_rrule; - (BOOL)hasRecurrenceRules; - (NSArray *)recurrenceRules; -- (NSArray *)recurrenceRulesWithTimeZone: (iCalTimeZone *) timezone; +- (NSArray *)recurrenceRulesWithTimeZone: (id) timezone; - (void)removeAllExceptionRules; - (void)addToExceptionRules:(id)_rrule; - (BOOL)hasExceptionRules; - (NSArray *)exceptionRules; -- (NSArray *)exceptionRulesWithTimeZone: (iCalTimeZone *) timezone; +- (NSArray *)exceptionRulesWithTimeZone: (id) timezone; - (void)removeAllExceptionDates; - (void)addToExceptionDates:(NSCalendarDate *)_date; - (BOOL)hasExceptionDates; - (NSArray *)exceptionDates; -- (NSArray *)exceptionDatesWithTimeZone: (iCalTimeZone*) theTimeZone; +- (NSArray *)exceptionDatesWithTimeZone: (id) theTimeZone; -- (NSArray *) rules: (NSArray *) theRules withTimeZone: (iCalTimeZone *) theTimeZone; +- (NSArray *) rules: (NSArray *) theRules withTimeZone: (id) theTimeZone; - (BOOL)isRecurrent; - (BOOL)isWithinCalendarDateRange:(NGCalendarDateRange *)_range diff --git a/SOPE/NGCards/iCalRepeatableEntityObject.m b/SOPE/NGCards/iCalRepeatableEntityObject.m index b2e9a00e6..5f675e29e 100644 --- a/SOPE/NGCards/iCalRepeatableEntityObject.m +++ b/SOPE/NGCards/iCalRepeatableEntityObject.m @@ -1,6 +1,6 @@ /* Copyright (C) 2004-2005 SKYRIX Software AG - Copyright (C) 2011 Inverse inc. + Copyright (C) 2012 Inverse inc. This file is part of SOPE. @@ -24,10 +24,12 @@ #import #import #import +#import #import #import "NSCalendarDate+NGCards.h" +#import "NSString+NGCards.h" #import "iCalDateTime.h" #import "iCalEvent.h" #import "iCalTimeZone.h" @@ -79,7 +81,7 @@ return [self childrenWithTag: @"rrule"]; } -- (NSArray *) recurrenceRulesWithTimeZone: (iCalTimeZone *) timezone +- (NSArray *) recurrenceRulesWithTimeZone: (id) timezone { NSArray *rules; @@ -113,7 +115,7 @@ return [self childrenWithTag: @"exrule"]; } -- (NSArray *) exceptionRulesWithTimeZone: (iCalTimeZone *) timezone +- (NSArray *) exceptionRulesWithTimeZone: (id) timezone { NSArray *rules; @@ -131,12 +133,13 @@ * @see exceptionRulesWithTimeZone: * @return a new array of iCalRecurrenceRule instances, adjusted for the timezone. */ -- (NSArray *) rules: (NSArray *) theRules withTimeZone: (iCalTimeZone *) theTimeZone +- (NSArray *) rules: (NSArray *) theRules withTimeZone: (id) theTimeZone { NSArray *rules; NSCalendarDate *untilDate; NSMutableArray *fixedRules; iCalRecurrenceRule *currentRule; + int offset; unsigned int max, count; rules = theRules; @@ -152,7 +155,14 @@ untilDate = [currentRule untilDate]; if (untilDate) { - untilDate = [theTimeZone computedDateForDate: untilDate]; + if ([theTimeZone isKindOfClass: [iCalTimeZone class]]) + untilDate = [(iCalTimeZone *) theTimeZone computedDateForDate: untilDate]; + else + { + offset = [(NSTimeZone *) theTimeZone secondsFromGMTForDate: untilDate]; + untilDate = (NSCalendarDate *) [untilDate dateByAddingYears:0 months:0 days:0 hours:0 minutes:0 + seconds:-offset]; + } [currentRule setUntilDate: untilDate]; } [fixedRules addObject: currentRule]; @@ -232,12 +242,13 @@ * @see [iCalTimeZone computedDatesForStrings:] * @return the exception dates, adjusted to the timezone. */ -- (NSArray *) exceptionDatesWithTimeZone: (iCalTimeZone *) theTimeZone +- (NSArray *) exceptionDatesWithTimeZone: (id) theTimeZone { NSArray *dates, *exDates; NSEnumerator *dateList; NSCalendarDate *exDate; NSString *dateString; + int offset; unsigned i; if (theTimeZone) @@ -251,9 +262,19 @@ for (i = 0; i < [exDates count]; i++) { dateString = [exDates objectAtIndex: i]; - exDate = [theTimeZone computedDateForString: dateString]; + if ([theTimeZone isKindOfClass: [iCalTimeZone class]]) + { + exDate = [(iCalTimeZone *) theTimeZone computedDateForString: dateString]; + } + else + { + exDate = [dateString asCalendarDate]; + offset = [(NSTimeZone *) theTimeZone secondsFromGMTForDate: exDate]; + exDate = (NSCalendarDate *) [exDate dateByAddingYears:0 months:0 days:0 hours:0 minutes:0 + seconds:-offset]; + } [(NSMutableArray *) dates addObject: exDate]; - } + } } } else diff --git a/SoObjects/Appointments/iCalRepeatableEntityObject+SOGo.m b/SoObjects/Appointments/iCalRepeatableEntityObject+SOGo.m index 04e6f93b3..d15760f64 100644 --- a/SoObjects/Appointments/iCalRepeatableEntityObject+SOGo.m +++ b/SoObjects/Appointments/iCalRepeatableEntityObject+SOGo.m @@ -125,9 +125,7 @@ NSArray *ranges; NGCalendarDateRange *checkRange, *firstRange; NSCalendarDate *startDate, *endDate; - NSTimeZone *timeZone; - id firstStartDate, firstEndDate; - iCalTimeZone *eventTimeZone; + id firstStartDate, firstEndDate, timeZone; BOOL doesOccur; int offset; @@ -139,9 +137,11 @@ // Set the range to check with respect to the event timezone (extracted from the start date) firstStartDate = (iCalDateTime *)[self uniqueChildWithTag: @"dtstart"]; - eventTimeZone = [(iCalDateTime *)firstStartDate timeZone]; - if (eventTimeZone) - startDate = [eventTimeZone computedDateForDate: theOccurenceDate]; + timeZone = [(iCalDateTime *)firstStartDate timeZone]; + if (timeZone) + { + startDate = [(iCalTimeZone *)timeZone computedDateForDate: theOccurenceDate]; + } else { startDate = theOccurenceDate; @@ -150,13 +150,14 @@ // The event lasts all-day and has no timezone (floating); we convert the range of the first event // to the occurence's timezone. timeZone = [theOccurenceDate timeZone]; - offset = [timeZone secondsFromGMTForDate: [firstRange startDate]]; + offset = [(NSTimeZone *)timeZone secondsFromGMTForDate: [firstRange startDate]]; firstStartDate = (NSCalendarDate *)[[firstRange startDate] dateByAddingYears:0 months:0 days:0 hours:0 minutes:0 seconds:-offset]; firstEndDate = (NSCalendarDate *)[[firstRange endDate] dateByAddingYears:0 months:0 days:0 hours:0 minutes:0 seconds:-offset]; [(NSCalendarDate *)firstStartDate setTimeZone: timeZone]; [(NSCalendarDate *)firstEndDate setTimeZone: timeZone]; + firstRange = [NGCalendarDateRange calendarDateRangeWithStartDate: firstStartDate endDate: firstEndDate]; } @@ -168,9 +169,9 @@ // Calculate the occurrences for the given date ranges = [iCalRecurrenceCalculator recurrenceRangesWithinCalendarDateRange: checkRange firstInstanceCalendarDateRange: firstRange - recurrenceRules: [self recurrenceRulesWithTimeZone: eventTimeZone] - exceptionRules: [self exceptionRulesWithTimeZone: eventTimeZone] - exceptionDates: [self exceptionDatesWithTimeZone: eventTimeZone]]; + recurrenceRules: [self recurrenceRulesWithTimeZone: timeZone] + exceptionRules: [self exceptionRulesWithTimeZone: timeZone] + exceptionDates: [self exceptionDatesWithTimeZone: timeZone]]; doesOccur = [ranges dateRangeArrayContainsDate: startDate]; }