From eea9b8b91d0f836979592907721095532fc0d2c6 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Tue, 29 Mar 2011 23:22:08 +0000 Subject: [PATCH] See ChangeLog. Monotone-Parent: 4a37382e84f4a00ccbbc0542ef0ae4a99a954cdd Monotone-Revision: 5768aec2a733241a4cb94db69e98b57603adb638 Monotone-Author: flachapelle@inverse.ca Monotone-Date: 2011-03-29T23:22:08 Monotone-Branch: ca.inverse.sogo --- SOPE/NGCards/ChangeLog | 10 ++++ SOPE/NGCards/iCalRepeatableEntityObject.h | 6 +- SOPE/NGCards/iCalRepeatableEntityObject.m | 69 +++++++++++++++++++++-- 3 files changed, 79 insertions(+), 6 deletions(-) diff --git a/SOPE/NGCards/ChangeLog b/SOPE/NGCards/ChangeLog index cf8baa08d..045ab9989 100644 --- a/SOPE/NGCards/ChangeLog +++ b/SOPE/NGCards/ChangeLog @@ -1,3 +1,13 @@ +2011-03-29 Francis Lachapelle + + * iCalRepeatableEntityObject.m (-rules:withEventTimeZone:): new + method that returns a new set of rules with their "untill dates" + adjusted to the specified timezone. + (-recurrenceRulesWithTimeZone:): new method that returns the + recurrence rules adjusted to the specified timezone. + (-exceptionRulesWithTimeZone:): new method that returns the + exception rules adjusted to the specified timezone. + 2011-03-23 Francis Lachapelle * iCalRepeatableEntityObject.m (-removeAllExceptionDates): don't diff --git a/SOPE/NGCards/iCalRepeatableEntityObject.h b/SOPE/NGCards/iCalRepeatableEntityObject.h index c1d5bae02..ea70b3486 100644 --- a/SOPE/NGCards/iCalRepeatableEntityObject.h +++ b/SOPE/NGCards/iCalRepeatableEntityObject.h @@ -47,17 +47,21 @@ - (void)setRecurrenceRules:(NSArray *)_rrule; - (BOOL)hasRecurrenceRules; - (NSArray *)recurrenceRules; +- (NSArray *)recurrenceRulesWithTimeZone: (iCalTimeZone *) timezone; - (void)removeAllExceptionRules; - (void)addToExceptionRules:(id)_rrule; - (BOOL)hasExceptionRules; - (NSArray *)exceptionRules; +- (NSArray *)exceptionRulesWithTimeZone: (iCalTimeZone *) timezone; - (void)removeAllExceptionDates; - (void)addToExceptionDates:(NSCalendarDate *)_date; - (BOOL)hasExceptionDates; - (NSArray *)exceptionDates; -- (NSArray *)exceptionDatesWithEventTimeZone:(iCalTimeZone*)theTimeZone; +- (NSArray *)exceptionDatesWithTimeZone: (iCalTimeZone*) theTimeZone; + +- (NSArray *) rules: (NSArray *) theRules withTimeZone: (iCalTimeZone *) theTimeZone; - (BOOL)isRecurrent; - (BOOL)isWithinCalendarDateRange:(NGCalendarDateRange *)_range diff --git a/SOPE/NGCards/iCalRepeatableEntityObject.m b/SOPE/NGCards/iCalRepeatableEntityObject.m index 2e0ed93b4..e0507f3d3 100644 --- a/SOPE/NGCards/iCalRepeatableEntityObject.m +++ b/SOPE/NGCards/iCalRepeatableEntityObject.m @@ -1,6 +1,6 @@ /* Copyright (C) 2004-2005 SKYRIX Software AG - Copyright (C) 2010 Inverse inc. + Copyright (C) 2011 Inverse inc. This file is part of SOPE. @@ -78,6 +78,14 @@ return [self childrenWithTag: @"rrule"]; } +- (NSArray *) recurrenceRulesWithTimeZone: (iCalTimeZone *) timezone +{ + NSArray *rules; + + rules = [self recurrenceRules]; + return [self rules: rules withTimeZone: timezone]; +} + - (void) removeAllExceptionRules { [self removeChildren: [self exceptionRules]]; @@ -104,6 +112,57 @@ return [self childrenWithTag: @"exrule"]; } +- (NSArray *) exceptionRulesWithTimeZone: (iCalTimeZone *) timezone +{ + NSArray *rules; + + rules = [self exceptionRules]; + return [self rules: rules withTimeZone: timezone]; +} + +/** + * Returns a new set of rules, but with "until dates" adjusted to the + * specified timezone. + * Used when calculating a recurrence/exception rule. + * @param theRules the iCalRecurrenceRule instances + * @param theTimeZone the timezone of the entity. + * @see recurrenceRulesWithTimeZone: + * @see exceptionRulesWithTimeZone: + * @return a new array of iCalRecurrenceRule instances, adjusted for the timezone. + */ +- (NSArray *) rules: (NSArray *) theRules withTimeZone: (iCalTimeZone *) theTimeZone +{ + NSArray *rules; + NSCalendarDate *untilDate; + NSMutableArray *fixedRules; + iCalRecurrenceRule *currentRule; + unsigned int max, count; + + rules = theRules; + if (theTimeZone) + { + max = [rules count]; + if (max) + { + fixedRules = [NSMutableArray arrayWithCapacity: max]; + for (count = 0; count < max; count++) + { + currentRule = [rules objectAtIndex: count]; + untilDate = [currentRule untilDate]; + if (untilDate) + { + untilDate = [theTimeZone computedDateForDate: untilDate]; + [currentRule setUntilDate: untilDate]; + } + [fixedRules addObject: currentRule]; + } + rules = fixedRules; + } + } + + return rules; +} + - (void) removeAllExceptionDates { [self removeChildren: [self childrenWithTag: @"exdate"]]; @@ -163,13 +222,13 @@ } /** - * Returns the exception dates for the event, but adjusted to the event timezone. + * Returns the exception dates for the entity, but adjusted to the entity timezone. * Used when calculating a recurrence rule. - * @param theTimeZone the timezone of the event. + * @param theTimeZone the timezone of the entity. * @see [iCalTimeZone computedDatesForStrings:] - * @return the exception dates for the event, adjusted to the event timezone. + * @return the exception dates, adjusted to the timezone. */ -- (NSArray *) exceptionDatesWithEventTimeZone: (iCalTimeZone *) theTimeZone +- (NSArray *) exceptionDatesWithTimeZone: (iCalTimeZone *) theTimeZone { NSArray *dates, *exDates; NSEnumerator *dateList;