(fix) fixed handling of exdates and proper intersection for fbinfo (fixes #4051)

pull/278/head
Ludovic Marcotte 2017-03-03 14:13:25 -05:00
parent 2f56bb43be
commit 84deb2fe45
3 changed files with 10 additions and 9 deletions

View File

@ -161,10 +161,12 @@ static Class yearlyCalcClass = Nil;
+ (NSArray *) _dates: (NSArray *) dateList + (NSArray *) _dates: (NSArray *) dateList
withinRange: (NGCalendarDateRange *) limits withinRange: (NGCalendarDateRange *) limits
startingWithDate: (NGCalendarDateRange *) first
{ {
NSMutableArray *newDates; NSMutableArray *newDates;
NSEnumerator *dates; NSEnumerator *dates;
NSCalendarDate *currentDate; NSCalendarDate *currentDate;
NGCalendarDateRange *currentRange;
newDates = [NSMutableArray array]; newDates = [NSMutableArray array];
@ -173,7 +175,10 @@ static Class yearlyCalcClass = Nil;
{ {
if ([currentDate isKindOfClass: NSStringClass]) if ([currentDate isKindOfClass: NSStringClass])
currentDate = [(NSString *) currentDate asCalendarDate]; currentDate = [(NSString *) currentDate asCalendarDate];
if ([limits containsDate: currentDate])
currentRange = [NGCalendarDateRange calendarDateRangeWithStartDate: currentDate
endDate: [currentDate dateByAddingYears: 0 months: 0 days: 0 hours: 0 minutes: 0 seconds: [first duration]]];
if ([limits doesIntersectWithDateRange: currentRange])
[newDates addObject: currentDate]; [newDates addObject: currentDate];
} }
@ -191,7 +196,7 @@ static Class yearlyCalcClass = Nil;
unsigned int count, maxRanges; unsigned int count, maxRanges;
NSComparisonResult compare; NSComparisonResult compare;
dates = [[self _dates: exdates withinRange: limits] objectEnumerator]; dates = [[self _dates: exdates withinRange: limits startingWithDate: first] objectEnumerator];
while ((currentDate = [dates nextObject])) while ((currentDate = [dates nextObject]))
{ {
maxRanges = [ranges count]; maxRanges = [ranges count];

View File

@ -191,7 +191,7 @@
for (k = 0; k < [rangesInMonth count] && (repeatCount == 0 || count < repeatCount); k++) { for (k = 0; k < [rangesInMonth count] && (repeatCount == 0 || count < repeatCount); k++) {
//NSLog(@"*** YEARLY found %@ (count = %i)", [[rangesInMonth objectAtIndex: k] startDate], count); //NSLog(@"*** YEARLY found %@ (count = %i)", [[rangesInMonth objectAtIndex: k] startDate], count);
count++; count++;
if ([_r containsDateRange: [rangesInMonth objectAtIndex: k]]) if ([_r doesIntersectWithDateRange: [rangesInMonth objectAtIndex: k]])
{ {
[ranges addObject: [rangesInMonth objectAtIndex: k]]; [ranges addObject: [rangesInMonth objectAtIndex: k]];
//NSLog(@"*** YEARLY adding %@ (count = %i)", [[rangesInMonth objectAtIndex: k] startDate], count); //NSLog(@"*** YEARLY adding %@ (count = %i)", [[rangesInMonth objectAtIndex: k] startDate], count);
@ -215,7 +215,7 @@
end = [start addTimeInterval: [firstRange duration]]; end = [start addTimeInterval: [firstRange duration]];
r = [NGCalendarDateRange calendarDateRangeWithStartDate: start r = [NGCalendarDateRange calendarDateRangeWithStartDate: start
endDate: end]; endDate: end];
if ([_r containsDateRange: r] && (repeatCount == 0 || count < repeatCount)) if ([_r doesIntersectWithDateRange: r] && (repeatCount == 0 || count < repeatCount))
{ {
[ranges addObject: r]; [ranges addObject: r];
count++; count++;

View File

@ -1299,17 +1299,13 @@ firstInstanceCalendarDateRange: (NGCalendarDateRange *) fir
{ {
NSMutableArray *ma; NSMutableArray *ma;
NSDictionary *row; NSDictionary *row;
NSCalendarDate *rangeEndDate;
unsigned int count, max; unsigned int count, max;
max = [_records count]; max = [_records count];
ma = [NSMutableArray arrayWithCapacity: max]; ma = [NSMutableArray arrayWithCapacity: max];
// Adjust the range so it ends at midnight. This is necessary when calculating
// recurrences of all-day events.
rangeEndDate = [[_r endDate] dateByAddingYears:0 months:0 days:0 hours:0 minutes:0 seconds:1];
_r = [NGCalendarDateRange calendarDateRangeWithStartDate: [_r startDate] _r = [NGCalendarDateRange calendarDateRangeWithStartDate: [_r startDate]
endDate: rangeEndDate]; endDate: [_r endDate]];
for (count = 0; count < max; count++) for (count = 0; count < max; count++)
{ {