]> err.no Git - sope/commitdiff
bugfixes for cycle calculation, modified implementations with future extensions in...
authorznek <znek@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Tue, 15 Feb 2005 21:11:00 +0000 (21:11 +0000)
committerznek <znek@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Tue, 15 Feb 2005 21:11:00 +0000 (21:11 +0000)
git-svn-id: http://svn.opengroupware.org/SOPE/trunk@563 e4a50df8-12e2-0310-a44c-efbce7f8a7e3

sope-ical/NGiCal/ChangeLog
sope-ical/NGiCal/NGiCal.xcode/project.pbxproj
sope-ical/NGiCal/Version
sope-ical/NGiCal/iCalRecurrenceCalculator.m
sope-ical/NGiCal/iCalRecurrenceRule.h
sope-ical/NGiCal/iCalRecurrenceRule.m

index 45fe292c91b397ed04950f9aaaf130eeff97ab60..1ac9c8712e5746c681f8472e1dc78c670a5cf164 100644 (file)
@@ -1,5 +1,14 @@
 2005-02-15  Marcus Mueller  <znek@mulle-kybernetik.com>
 
+       * v4.5.43
+
+       * iCalRecurrenceRule.[hm]: exposed some more of the API
+
+       * iCalRecurrenceCalculator.m: some bugfixes. Split the code and gave
+         iCalWeeklyRecurrenceCalculator its own calculation - there are a
+         number of foreseeable differences to daily calculation that make
+         this necessary in the near future anyways.
+
        * v4.5.42
 
        * iCalRepeatableEntityObject.[hm]: added ability to properly calculate
index f7365484b30ee8724a7d0006f0699795687cd41d..fffebc1d721641dd5229b086947ca3a287a944f9 100644 (file)
                        );
                        buildSettings = {
                                DYLIB_COMPATIBILITY_VERSION = 1;
-                               DYLIB_CURRENT_VERSION = 4.5.42;
+                               DYLIB_CURRENT_VERSION = 4.5.43;
                                FRAMEWORK_SEARCH_PATHS = "\"$(USER_LIBRARY_DIR)/EmbeddedFrameworks\"";
                                FRAMEWORK_VERSION = A;
                                GCC_PRECOMPILE_PREFIX_HEADER = NO;
                        );
                        buildSettings = {
                                DYLIB_COMPATIBILITY_VERSION = 1;
-                               DYLIB_CURRENT_VERSION = 4.5.42;
+                               DYLIB_CURRENT_VERSION = 4.5.43;
                                FRAMEWORK_SEARCH_PATHS = "$(LOCAL_LIBRARY_DIR)/Frameworks";
                                FRAMEWORK_VERSION = A;
                                GCC_PRECOMPILE_PREFIX_HEADER = YES;
index 03d46ce9a32c4f20e301d4579fb8f69583c13111..116461db6eb45ca2d360a272c0f15c5e7c9029cd 100644 (file)
@@ -2,7 +2,7 @@
 
 MAJOR_VERSION=4
 MINOR_VERSION=5
-SUBMINOR_VERSION:=42
+SUBMINOR_VERSION:=43
 
 # v4.5.40 requires NGExtensions v4.5.145
 # v4.5.37 requires NGExtensions v4.5.140
index 83b57d8dfddf34fb369264d58eaa87ff3e7ba863..7878d45bcc6aa2ec3d049b382709e7c30c13b74d 100644 (file)
 @interface iCalDailyRecurrenceCalculator : iCalRecurrenceCalculator
 {
 }
-- (unsigned)factor;
 @end
 
-@interface iCalWeeklyRecurrenceCalculator : iCalDailyRecurrenceCalculator
+@interface iCalWeeklyRecurrenceCalculator : iCalRecurrenceCalculator
 {
 }
 @end
@@ -179,7 +178,7 @@ static Class yearlyCalcClass  = Nil;
       jnRuleLast = [until julianNumber];
     }
     else {
-      jnRuleLast = (interval * [self->rrule repeatCount] * [self factor])
+      jnRuleLast = (interval * [self->rrule repeatCount])
       + jnFirst;
       if (jnRuleLast < jnStart)
         return nil;
@@ -189,27 +188,31 @@ static Class yearlyCalcClass  = Nil;
       jnEnd = jnRuleLast;
   }
 
-  ranges        = [NSMutableArray arrayWithCapacity:5];
   startEndCount = (jnEnd - jnStart) + 1;
+  ranges        = [NSMutableArray arrayWithCapacity:startEndCount];
   for (i = 0 ; i < startEndCount; i++) {
-    long jnTest;
-
-    jnTest = (jnStart + i) - jnFirst;
-    if ((jnTest % interval) == 0) {
-      NSCalendarDate      *start, *end;
-      NGCalendarDateRange *r;
+    long jnCurrent;
     
-      start = [NSCalendarDate dateForJulianNumber:jnStart + i];
-      start = [start hour:  [firStart hourOfDay]
-                     minute:[firStart minuteOfHour]
-                     second:[firStart secondOfMinute]];
-      end   = [start addTimeInterval:[self->firstRange duration]];
-      r     = [NGCalendarDateRange calendarDateRangeWithStartDate:start
-                                   endDate:end];
-      [ranges addObject:r];
+    jnCurrent = jnStart + i;
+    if (jnCurrent >= jnFirst) {
+      long jnTest;
+      
+      jnTest = jnCurrent - jnFirst;
+      if ((jnTest % interval) == 0) {
+        NSCalendarDate      *start, *end;
+        NGCalendarDateRange *r;
+      
+        start = [NSCalendarDate dateForJulianNumber:jnCurrent];
+        start = [start hour:  [firStart hourOfDay]
+                       minute:[firStart minuteOfHour]
+                       second:[firStart secondOfMinute]];
+        end   = [start addTimeInterval:[self->firstRange duration]];
+        r     = [NGCalendarDateRange calendarDateRangeWithStartDate:start
+                                     endDate:end];
+        [ranges addObject:r];
+      }
     }
   }
-  
   return ranges;
 }
 
@@ -221,8 +224,7 @@ static Class yearlyCalcClass  = Nil;
     firStart   = [self->firstRange startDate];
     jnFirst    = [firStart julianNumber];
     jnRuleLast = ([self->rrule repeatInterval] *
-                  [self->rrule repeatCount] *
-                  [self factor]) +
+                  [self->rrule repeatCount]) +
                   jnFirst;
     until      = [NSCalendarDate dateForJulianNumber:jnRuleLast];
     until      = [until hour:  [firStart hourOfDay]
@@ -233,10 +235,6 @@ static Class yearlyCalcClass  = Nil;
   return [super lastInstanceStartDate];
 }
 
-- (unsigned)factor {
-  return 1;
-}
-
 @end /* iCalDailyRecurrenceCalculator */
 
 
@@ -246,8 +244,95 @@ static Class yearlyCalcClass  = Nil;
 */
 @implementation iCalWeeklyRecurrenceCalculator
 
-- (unsigned)factor {
-  return 7;
+- (NSArray *)recurrenceRangesWithinCalendarDateRange:(NGCalendarDateRange *)_r {
+  NSMutableArray *ranges;
+  NSCalendarDate *firStart;
+  long           i, jnFirst, jnStart, jnEnd, startEndCount;
+  unsigned       interval, byDayMask;
+
+  firStart = [self->firstRange startDate];
+  jnFirst  = [firStart julianNumber];
+  jnEnd    = [[_r endDate] julianNumber];
+  
+  if (jnFirst > jnEnd)
+    return nil;
+  
+  jnStart  = [[_r startDate] julianNumber];
+  interval = [self->rrule repeatInterval];
+  
+  /* if rule is bound, check the bounds */
+  if (![self->rrule isInfinite]) {
+    NSCalendarDate *until;
+    long           jnRuleLast;
+    
+    until = [self->rrule untilDate];
+    if (until) {
+      if ([until compare:[_r startDate]] == NSOrderedAscending)
+        return nil;
+      jnRuleLast = [until julianNumber];
+    }
+    else {
+      jnRuleLast = (interval * [self->rrule repeatCount] * 7)
+      + jnFirst;
+      if (jnRuleLast < jnStart)
+        return nil;
+    }
+    /* jnStart < jnRuleLast < jnEnd ? */
+    if (jnEnd > jnRuleLast)
+      jnEnd = jnRuleLast;
+  }
+  
+  startEndCount = (jnEnd - jnStart) + 1;
+  ranges        = [NSMutableArray arrayWithCapacity:startEndCount];
+  byDayMask     = [self->rrule byDayMask];
+  if (!byDayMask) {
+    for (i = 0 ; i < startEndCount; i++) {
+      long jnCurrent;
+      
+      jnCurrent = jnStart + i;
+      if (jnCurrent >= jnFirst) {
+        long jnDiff;
+        
+        jnDiff = jnCurrent - jnFirst; /* difference in days */
+        if ((jnDiff % (interval * 7)) == 0) {
+          NSCalendarDate      *start, *end;
+          NGCalendarDateRange *r;
+          
+          start = [NSCalendarDate dateForJulianNumber:jnCurrent];
+          start = [start hour:  [firStart hourOfDay]
+                         minute:[firStart minuteOfHour]
+                         second:[firStart secondOfMinute]];
+          end   = [start addTimeInterval:[self->firstRange duration]];
+          r     = [NGCalendarDateRange calendarDateRangeWithStartDate:start
+                                       endDate:end];
+          [ranges addObject:r];
+        }
+      }
+    }
+  }
+  else {
+    [self errorWithFormat:@"Cannot calculate rules with byDayMask, yet!"];
+  }
+  return ranges;
+}
+
+- (NSCalendarDate *)lastInstanceStartDate {
+  if ([self->rrule repeatCount] > 0) {
+    long           jnFirst, jnRuleLast;
+    NSCalendarDate *firStart, *until;
+    
+    firStart   = [self->firstRange startDate];
+    jnFirst    = [firStart julianNumber];
+    jnRuleLast = ([self->rrule repeatInterval] *
+                  [self->rrule repeatCount] * 7) +
+                  jnFirst;
+    until      = [NSCalendarDate dateForJulianNumber:jnRuleLast];
+    until      = [until hour:  [firStart hourOfDay]
+                        minute:[firStart minuteOfHour]
+                        second:[firStart secondOfMinute]];
+    return until;
+  }
+  return [super lastInstanceStartDate];
 }
 
 @end /* iCalWeeklyRecurrenceCalculator */
index eb1a5bf92f1ca90720b40caeffc6864ae816bd7c..96e77e949f1ff91a8935644379a04fdc6d659da7 100644 (file)
@@ -76,7 +76,11 @@ typedef enum {
 - (iCalRecurrenceFrequency)frequency;
 - (void)setRepeatInterval:(int)_repeatInterval;
 - (int)repeatInterval;
-
+- (void)setWeekStart:(iCalWeekDay)_weekStart;
+- (iCalWeekDay)weekStart;
+- (void)setByDayMask:(unsigned)_mask;
+- (unsigned)byDayMask;
+  
 /* count and untilDate are mutually exclusive */
 - (void)setRepeatCount:(unsigned)_repeatCount;
 - (unsigned)repeatCount;
index 9278888f6e37fcf9e809b790f2ee529c57199a45..4665b064e91c9a49f3c380c9b26a59e87f4aa572 100644 (file)
   return self->byDay.weekStart;
 }
 
+- (void)setByDayMask:(unsigned)_mask {
+  self->byDay.mask = _mask;
+}
+- (unsigned)byDayMask {
+  return self->byDay.mask;
+}
+
 - (BOOL)isInfinite {
   return (self->repeatCount != 0 || self->untilDate) ? NO : YES;
 }