]> err.no Git - sope/commitdiff
implemented negative occurences
authorhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Wed, 5 Oct 2005 16:06:58 +0000 (16:06 +0000)
committerhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Wed, 5 Oct 2005 16:06:58 +0000 (16:06 +0000)
git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1161 e4a50df8-12e2-0310-a44c-efbce7f8a7e3

sope-ical/NGiCal/ChangeLog
sope-ical/NGiCal/Version
sope-ical/NGiCal/iCalMonthlyRecurrenceCalculator.m

index c64773b4a1798569a110daf559b58a0a24e02f9f..775c367ed2519bda9a1c52aee123f7afc142c350 100644 (file)
@@ -1,3 +1,8 @@
+2005-10-05  Helge Hess  <helge.hess@opengroupware.org>
+
+       * iCalMonthlyRecurrenceCalculator.m: implemented calculation of
+         negative byday occurrences (eg -1TH) (v4.5.69)
+
 2005-09-22  Helge Hess  <helge.hess@skyrix.com>
 
        * iCalRecurrenceRule.m: added direct parser support for 'interval',
index 59e4f30b7c28035b49b0b0e7bd17efa62064029c..e00463656a9765b86c03f403e2613b188dc1fc12 100644 (file)
@@ -2,7 +2,7 @@
 
 MAJOR_VERSION=4
 MINOR_VERSION=5
-SUBMINOR_VERSION:=68
+SUBMINOR_VERSION:=69
 
 # v4.5.40 requires NGExtensions v4.5.145
 # v4.5.37 requires NGExtensions v4.5.140
index 2bfcdf5d6ce3f44b52031fe9af41c9a68db6dc5d..e54b224d3a9306707b725385e03eaae58637686e 100644 (file)
@@ -33,6 +33,8 @@
 - (NSCalendarDate *)lastInstanceStartDate;
 @end
 
+// #define HEAVY_DEBUG 1
+
 @implementation iCalMonthlyRecurrenceCalculator
 
 typedef BOOL NGMonthSet[12];
@@ -111,34 +113,89 @@ static inline unsigned iCalDoWForNSDoW(int dow) {
   }
 }
 
+#if HEAVY_DEBUG
+static NSString *dowEN[8] = { 
+  @"SU", @"MO", @"TU", @"WE", @"TH", @"FR", @"SA", @"SU-"
+};
+#endif
+
 static void NGMonthDaySet_fillWithByDayX(NGMonthDaySet *daySet, 
                                          unsigned dayMask,
                                         unsigned firstDoWInMonth,
+                                        unsigned numberOfDaysInMonth,
                                          int occurrence1)
 {
   // TODO: this is called 'X' because the API doesn't allow for full iCalendar
   //       functionality. The daymask must be a list of occurence+dow
   register unsigned dayInMonth;
-  register unsigned dow; /* current day of the week */
+  register int dow; /* current day of the week */
   int occurrences[7] = { 0, 0, 0, 0, 0, 0, 0 } ;
   
   NGMonthDaySet_clear(daySet);
   
-  for (dayInMonth = 1, dow = firstDoWInMonth; dayInMonth <= 31; dayInMonth++) {
-    // TODO: complete me
+  if (occurrence1 >= 0) {
+    for (dayInMonth = 1, dow = firstDoWInMonth; dayInMonth<=31; dayInMonth++) {
+      // TODO: complete me
+      
+      if (dayMask & iCalDoWForNSDoW(dow)) {
+        if (occurrence1 == 0)
+         (*daySet)[dayInMonth] = YES;
+        else { /* occurrence1 > 0 */
+         occurrences[dow] = occurrences[dow] + 1;
+         
+         if (occurrences[dow] == occurrence1) 
+           (*daySet)[dayInMonth] = YES;
+        }
+      }
+      
+      dow = (dow == 6 /* Sat */) ? 0 /* Sun */ : (dow + 1);
+    }
+  }
+  else {
+    int lastDoWInMonthSet;
     
-    if (dayMask & iCalDoWForNSDoW(dow)) {
-      if (occurrence1 == 0)
-       (*daySet)[dayInMonth] = YES;
-      else {
+    /* get the last dow in the set (not necessarily the month!) */
+    for (dayInMonth = 1, dow = firstDoWInMonth; 
+        dayInMonth < numberOfDaysInMonth;dayInMonth++)
+      dow = (dow == 6 /* Sat */) ? 0 /* Sun */ : (dow + 1);
+    lastDoWInMonthSet = dow;
+    
+#if HEAVY_DEBUG
+    NSLog(@"LAST DOW IN SET: %i / %@", 
+         lastDoWInMonthSet, dowEN[lastDoWInMonthSet]);
+#endif
+    /* start at the end of the set */
+    for (dayInMonth = numberOfDaysInMonth, dow = lastDoWInMonthSet; 
+        dayInMonth >= 1; dayInMonth--) {
+      // TODO: complete me
+      
+#if HEAVY_DEBUG
+      NSLog(@"  CHECK day-of-month %02i, "
+           @" dow=%i/%@ (first=%i/%@, last=%i/%@)",
+           dayInMonth, 
+           dow, dowEN[dow],
+           firstDoWInMonth, dowEN[firstDoWInMonth],
+           lastDoWInMonthSet, dowEN[lastDoWInMonthSet]
+           );
+#endif
+      
+      if (dayMask & iCalDoWForNSDoW(dow)) {
        occurrences[dow] = occurrences[dow] + 1;
-       
-       if (occurrences[dow] == occurrence1) 
+#if HEAVY_DEBUG
+       NSLog(@"    MATCH %i/%@ count: %i occurences=%i",
+             dow, dowEN[dow], occurrences[dow], occurrence1);
+#endif
+         
+       if (occurrences[dow] == -occurrence1) {
+#if HEAVY_DEBUG
+         NSLog(@"    COUNT MATCH");
+#endif
          (*daySet)[dayInMonth] = YES;
+       }
       }
+      
+      dow = (dow == 0 /* Sun */) ? 6 /* Sat */ : (dow - 1);
     }
-    
-    dow = (dow == 6 /* Sat */) ? 0 /* Sun */ : (dow + 1);
   }
 }
 
@@ -289,6 +346,7 @@ static void NGMonthDaySet_fillWithByDayX(NGMonthDaySet *daySet,
       NGMonthDaySet_fillWithByDayX(&ruleset, 
                                    [self->rrule byDayMask],
                                   firstDoWInMonth,
+                                  [cursor numberOfDaysInMonth],
                                    [self->rrule byDayOccurence1]);
       NGMonthDaySet_copyOrUnion(&monthDays, &ruleset, !didByFill);
       didByFill = YES;