From 0bc20fee04c87eac5238821a1d82e4c5c2ed1309 Mon Sep 17 00:00:00 2001 From: wolfgang Date: Mon, 28 Jan 2008 18:52:11 +0000 Subject: [PATCH] git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1343 d1b88da0-ebda-0310-925b-ed51d893ca5b --- SOPE/NGCards/ChangeLog | 7 ++++ SOPE/NGCards/iCalRecurrenceRule.m | 55 ++++++++++++++++++++----------- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/SOPE/NGCards/ChangeLog b/SOPE/NGCards/ChangeLog index b66b3e49..8fd11bd8 100644 --- a/SOPE/NGCards/ChangeLog +++ b/SOPE/NGCards/ChangeLog @@ -1,5 +1,12 @@ 2008-01-28 Wolfgang Sourdeau + * iCalRecurrenceRule.m ([iCalRecurrenceRule + -weekDayFromICalRepresentation:_day]): issue an error whenever the + day cannot be deduced. Accept days notated with a prefix. + ([iCalRecurrenceRule -byDayMask]): don't strip the represented + day, feed it directly to weekDayFromICalRepresentation: since it + will do the correct syntax validation. + * iCalDailyRecurrenceCalculator.m ([iCalDailyRecurrenceCalculator -recurrenceRangesWithinCalendarDateRange:]): make use of << instead of exp2 to compute the mask. diff --git a/SOPE/NGCards/iCalRecurrenceRule.m b/SOPE/NGCards/iCalRecurrenceRule.m index bc4efc4c..97fb294d 100644 --- a/SOPE/NGCards/iCalRecurrenceRule.m +++ b/SOPE/NGCards/iCalRecurrenceRule.m @@ -302,7 +302,6 @@ for (count = 0; count < max; count++) { day = [days objectAtIndex: count]; - day = [day substringFromIndex: [day length] - 2]; mask |= [self weekDayFromICalRepresentation: day]; } } @@ -331,27 +330,43 @@ - (iCalWeekDay) weekDayFromICalRepresentation: (NSString *) _day { - if ([_day length] > 1) { - /* be tolerant */ - unichar c0, c1; - - c0 = [_day characterAtIndex:0]; - if (c0 == 'm' || c0 == 'M') return iCalWeekDayMonday; - if (c0 == 'w' || c0 == 'W') return iCalWeekDayWednesday; - if (c0 == 'f' || c0 == 'F') return iCalWeekDayFriday; - - c1 = [_day characterAtIndex:1]; - if (c0 == 't' || c0 == 'T') { - if (c1 == 'u' || c1 == 'U') return iCalWeekDayTuesday; - if (c1 == 'h' || c1 == 'H') return iCalWeekDayThursday; - } - if (c0 == 's' || c0 == 'S') { - if (c1 == 'a' || c1 == 'A') return iCalWeekDaySaturday; - if (c1 == 'u' || c1 == 'U') return iCalWeekDaySunday; + NSString *day; + /* be tolerant */ + iCalWeekDay foundDay; + unichar chars[2]; + + foundDay = 0; + + if ([_day length] > 1) + { + [[_day uppercaseString] getCharacters: chars + range: NSMakeRange ([day length] - 2, 2)]; + + switch (chars[0]) + { + case 'M': foundDay = iCalWeekDayMonday; + break; + case 'W': foundDay = iCalWeekDayWednesday; + break; + case 'F': foundDay = iCalWeekDayFriday; + break; + case 'T': + if (chars[1] == 'U') + foundDay = iCalWeekDayTuesday; + else if (chars[1] == 'H') + foundDay = iCalWeekDayThursday; + case 'S': + if (chars[1] == 'A') + foundDay = iCalWeekDaySaturday; + else if (chars[1] == 'H') + foundDay = iCalWeekDaySunday; + } } - } - return -1; + if (!foundDay) + [self errorWithFormat: @"wrong weekday representation: '%@'", _day]; + + return foundDay; // // TODO: do not raise but rather return an error value? // [NSException raise:NSGenericException // format:@"Incorrect weekDay '%@' specified!", _day]; -- 2.39.5