]> err.no Git - sope/commitdiff
improved byday support
authorhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Mon, 19 Sep 2005 22:17:56 +0000 (22:17 +0000)
committerhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Mon, 19 Sep 2005 22:17:56 +0000 (22:17 +0000)
git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1117 e4a50df8-12e2-0310-a44c-efbce7f8a7e3

sope-ical/NGiCal/ChangeLog
sope-ical/NGiCal/Version
sope-ical/NGiCal/iCalRecurrenceRule.h
sope-ical/NGiCal/iCalRecurrenceRule.m

index ebe1c60d375de154cf8878d9a691ea19b3b759ae..77a68ba47980d9915973be56da04f2066df6601f 100644 (file)
@@ -1,3 +1,8 @@
+2005-09-20  Helge Hess  <helge.hess@opengroupware.org>
+
+       * iCalRecurrenceRule.m: added some parsing/gen support for BYDAY
+         (v4.5.62)
+
 2005-09-19  Helge Hess  <helge.hess@opengroupware.org>
 
        * iCalRecurrenceRule.m: minor code improvements, more tolerant on
index 1b7555321ef1c4b6a29b8ad5ac6d567fd48d40ad..2075e285c655698aad736b8cc4f6857b1ee301ea 100644 (file)
@@ -2,7 +2,7 @@
 
 MAJOR_VERSION=4
 MINOR_VERSION=5
-SUBMINOR_VERSION:=61
+SUBMINOR_VERSION:=62
 
 # v4.5.40 requires NGExtensions v4.5.145
 # v4.5.37 requires NGExtensions v4.5.140
index 9cc99901386676e2d3b90a0d415b09f283936c8e..45d42b757d5a50899fe4ac7bed51bae25f5785bc 100644 (file)
@@ -34,6 +34,7 @@
         Please see the unit tests for what is covered.
 */
 
+// TODO: we could use string constants?
 typedef enum {
   iCalRecurrenceFrequenceSecondly = 1,
   iCalRecurrenceFrequenceMinutely = 2,
@@ -65,7 +66,10 @@ typedef enum {
   struct {
     unsigned weekStart: 7;
     unsigned mask:      7;
+    unsigned useOccurence:1;
+    unsigned reserved:1;
   } byDay;
+  int byDayOccurence1;
 
   NSString       *rrule;
 }
index 55a1a1db2af1700838885290e8dce59cff9d1f6f..7a03c4673aff7f467c015006847992af46e7965e 100644 (file)
     if (c0 == 'f' || c0 == 'F') return iCalWeekDayFriday;
 
     c1 = [_day characterAtIndex:1];
-    if (c0 == 't' || c0 == 't') {
+    if (c0 == 't' || c0 == 'T') {
       if (c1 == 'u' || c1 == 'U') return iCalWeekDayTuesday;
       if (c1 == 'h' || c1 == 'H') return iCalWeekDayThursday;
     }
   NSMutableString *s;
   unsigned        i, mask, day;
   BOOL            needsComma;
-
+  
   s          = [NSMutableString stringWithCapacity:20];
   needsComma = NO;
   mask       = self->byDay.mask;
     if (mask & day) {
       if (needsComma)
         [s appendString:@","];
+      else if (self->byDay.useOccurence)
+       // Note: we only support one occurrence currently
+       [s appendFormat:@"%i", self->byDayOccurence1];
+      
       [s appendString:[self iCalRepresentationForWeekDay:day]];
       needsComma = YES;
     }
 /* properties */
 
 - (void)setFreq:(NSString *)_freq {
+  // TODO: shouldn't we preserve what the user gives us?
   _freq = [_freq uppercaseString];
   if ([_freq isEqualToString:@"WEEKLY"])
     self->frequency = iCalRecurrenceFrequenceWeekly;
 }
 
 - (void)setByday:(NSString *)_byDayList {
+  // TODO: each day can have an associated occurence, eg:
+  //        +1MO,+2TU,-9WE
   NSArray  *days;
   unsigned i, count;
-
+  
+  /* reset mask */
   self->byDay.mask = 0;
+  self->byDay.useOccurence = 0;
+  self->byDayOccurence1 = 0;
+  
   days  = [_byDayList componentsSeparatedByString:@","];
   for (i = 0, count = [days count]; i < count; i++) {
     NSString    *iCalDay;
     iCalWeekDay day;
+    unsigned    len;
+    unichar     c0;
+    int         occurence;
+    
+    iCalDay = [days objectAtIndex:i]; // eg: MO or TU
+    if ((len = [iCalDay length]) == 0) {
+      [self errorWithFormat:@"found an empty day in byday list: '%@'", 
+             _byDayList];
+      continue;
+    }
+    
+    c0 = [iCalDay characterAtIndex:0];
+    if (((c0 == '+' || c0 == '-') && len > 2) || (isdigit(c0) && len > 1)) {
+      int offset;
+      
+      occurence = [iCalDay intValue];
+
+      offset = 1;
+      while (offset < len && isdigit([iCalDay characterAtIndex:offset]))
+       offset++;
+      
+      iCalDay = [iCalDay substringFromIndex:offset];
+      
+      if (self->byDay.useOccurence) {
+       [self errorWithFormat:
+               @"we only supported one occurence (occ=%i,day=%@): '%@'", 
+               occurence, iCalDay, _byDayList];
+       continue;
+      }
+      
+      self->byDay.useOccurence = 1;
+      self->byDayOccurence1 = occurence;
+    }
+    else if (self->byDay.useOccurence) {
+      [self errorWithFormat:
+             @"a byday occurence was specified on one day, but not on others"
+             @" (unsupported): '%@'", _byDayList];
+    }
     
-    iCalDay = [days objectAtIndex:i];
-    day     = [self weekDayFromICalRepresentation:iCalDay];
+    day = [self weekDayFromICalRepresentation:iCalDay];
     self->byDay.mask |= day;
   }
 }
   return s;
 }
 
+- (NSString *)description {
+  return [self iCalRepresentation];
+}
+
 @end /* iCalRecurrenceRule */