Fixed bug with timezone and recurrent events.
Monotone-Parent: bc6abe537500d635cea12c3c4f611e68d4c2d725 Monotone-Revision: 792193186b20895dc235fa98dc63de1a0ece0a8f Monotone-Author: flachapelle@inverse.ca Monotone-Date: 2008-12-19T22:14:02 Monotone-Branch: ca.inverse.sogomaint-2.0.2
parent
64eb68a085
commit
7f602d5dba
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
2008-12-19 Francis Lachapelle <flachapelle@inverse.ca>
|
||||
|
||||
* iCalWeeklyRecurrenceCalculator.m ([iCalDailyRecurrenceCalculator
|
||||
-recurrenceRangesWithinCalendarDateRange:_r]): rewrote method to
|
||||
handle timezones. Removed usage of julian numbers.
|
||||
|
||||
* iCalDailyRecurrenceCalculator.m ([iCalWeeklyRecurrenceCalculator
|
||||
-recurrenceRangesWithinCalendarDateRange:_r]): idem. Also fixed
|
||||
the handling of intervals.
|
||||
|
||||
2008-12-17 Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
|
||||
* SoObjects/SOGo/SOGoParentFolder.m ([SOGoParentFolder
|
||||
|
|
|
@ -43,87 +43,78 @@
|
|||
recurrenceRangesWithinCalendarDateRange: (NGCalendarDateRange *) _r
|
||||
{
|
||||
NSMutableArray *ranges;
|
||||
NSCalendarDate *firStart;
|
||||
long i, jnFirst, jnStart, jnEnd, startEndCount;
|
||||
NSCalendarDate *firStart, *startDate, *endDate, *currentStartDate, *currentEndDate;
|
||||
long i;
|
||||
unsigned interval;
|
||||
|
||||
firStart = [firstRange startDate];
|
||||
jnFirst = [firStart julianNumber];
|
||||
jnEnd = [[_r endDate] julianNumber];
|
||||
startDate = [_r startDate];
|
||||
endDate = [_r endDate];
|
||||
|
||||
if (jnFirst > jnEnd)
|
||||
if ([endDate compare: firStart] == NSOrderedAscending)
|
||||
// Range ends before first occurrence
|
||||
return nil;
|
||||
|
||||
jnStart = [[_r startDate] julianNumber];
|
||||
interval = [rrule repeatInterval];
|
||||
|
||||
/* if rule is bound, check the bounds */
|
||||
// If rule is bound, check the bounds
|
||||
if (![rrule isInfinite])
|
||||
{
|
||||
NSCalendarDate *until;
|
||||
long jnRuleLast;
|
||||
NSCalendarDate *until, *lastDate;
|
||||
|
||||
until = [rrule untilDate];
|
||||
if (until)
|
||||
{
|
||||
if ([until compare: [_r startDate]] == NSOrderedAscending)
|
||||
return nil;
|
||||
jnRuleLast = [until julianNumber];
|
||||
}
|
||||
lastDate = until;
|
||||
else
|
||||
{
|
||||
jnRuleLast = (interval * [rrule repeatCount])
|
||||
+ jnFirst - 1;
|
||||
if (jnRuleLast < jnStart)
|
||||
lastDate = [firStart dateByAddingYears: 0 months: 0
|
||||
days: (interval
|
||||
* ([rrule repeatCount] - 1))];
|
||||
|
||||
if ([lastDate compare: startDate] == NSOrderedAscending)
|
||||
// Range starts after last occurrence
|
||||
return nil;
|
||||
}
|
||||
/* jnStart < jnRuleLast < jnEnd ? */
|
||||
if (jnEnd > jnRuleLast)
|
||||
jnEnd = jnRuleLast;
|
||||
|
||||
if ([lastDate compare: endDate] == NSOrderedAscending)
|
||||
// Range ends after last occurence; adjust end date
|
||||
endDate = lastDate;
|
||||
}
|
||||
|
||||
startEndCount = (jnEnd - jnStart) + 1;
|
||||
ranges = [NSMutableArray arrayWithCapacity:startEndCount];
|
||||
for (i = 0 ; i < startEndCount; i++)
|
||||
{
|
||||
long jnCurrent;
|
||||
currentStartDate = [firStart copy];
|
||||
ranges = [NSMutableArray array];
|
||||
i = 1;
|
||||
|
||||
jnCurrent = jnStart + i;
|
||||
if (jnCurrent >= jnFirst)
|
||||
while ([currentStartDate compare: endDate] == NSOrderedAscending ||
|
||||
[currentStartDate compare: endDate] == NSOrderedSame)
|
||||
{
|
||||
long jnTest;
|
||||
|
||||
jnTest = jnCurrent - jnFirst;
|
||||
if ((jnTest % interval) == 0)
|
||||
if ([startDate compare: currentStartDate] == NSOrderedAscending ||
|
||||
[startDate compare: currentStartDate] == NSOrderedSame)
|
||||
{
|
||||
NSCalendarDate *start, *end;
|
||||
NGCalendarDateRange *r;
|
||||
BOOL wrongDay = NO;
|
||||
unsigned int mask;
|
||||
NGCalendarDateRange *r;
|
||||
|
||||
start = [NSCalendarDate dateForJulianNumber:jnCurrent];
|
||||
[start setTimeZone: [firStart timeZone]];
|
||||
start = [start hour: [firStart hourOfDay]
|
||||
minute: [firStart minuteOfHour]
|
||||
second: [firStart secondOfMinute]];
|
||||
end = [start addTimeInterval: [firstRange duration]];
|
||||
|
||||
// We check if our start date is within the byDayMask
|
||||
// FIXME: Should we also check the end date? We might want
|
||||
// to check if the end date is also within it.
|
||||
if ([rrule byDayMask])
|
||||
{
|
||||
mask = ([start dayOfWeek]
|
||||
? (unsigned int) 1 << ([start dayOfWeek])
|
||||
mask = ([currentStartDate dayOfWeek]
|
||||
? (unsigned int) 1 << ([currentStartDate dayOfWeek])
|
||||
: iCalWeekDaySunday);
|
||||
if (([rrule byDayMask]&mask) != mask) continue;
|
||||
if (([rrule byDayMask] & mask) != mask)
|
||||
wrongDay = YES;
|
||||
}
|
||||
|
||||
r = [NGCalendarDateRange calendarDateRangeWithStartDate:start
|
||||
endDate:end];
|
||||
if ([_r containsDateRange:r])
|
||||
[ranges addObject:r];
|
||||
if (wrongDay == NO)
|
||||
{
|
||||
currentEndDate = [currentStartDate addTimeInterval: [firstRange duration]];
|
||||
r = [NGCalendarDateRange calendarDateRangeWithStartDate: currentStartDate
|
||||
endDate: currentEndDate];
|
||||
if ([_r containsDateRange: r])
|
||||
[ranges addObject: r];
|
||||
}
|
||||
}
|
||||
|
||||
currentStartDate = [firStart dateByAddingYears: 0 months: 0
|
||||
days: (interval * i)];
|
||||
i++;
|
||||
}
|
||||
return ranges;
|
||||
}
|
||||
|
|
|
@ -48,140 +48,122 @@
|
|||
*/
|
||||
@implementation iCalWeeklyRecurrenceCalculator
|
||||
|
||||
- (NSArray *)
|
||||
recurrenceRangesWithinCalendarDateRange: (NGCalendarDateRange *) _r
|
||||
- (NSArray *) recurrenceRangesWithinCalendarDateRange: (NGCalendarDateRange *) _r
|
||||
{
|
||||
NSMutableArray *ranges;
|
||||
NSCalendarDate *firStart;
|
||||
long i, jnFirst, jnStart, jnEnd, startEndCount;
|
||||
NSCalendarDate *firStart, *startDate, *endDate, *currentStartDate, *currentEndDate;
|
||||
long i;
|
||||
unsigned interval, byDayMask;
|
||||
|
||||
firStart = [firstRange startDate];
|
||||
jnFirst = [firStart julianNumber];
|
||||
jnEnd = [[_r endDate] julianNumber];
|
||||
startDate = [_r startDate];
|
||||
endDate = [_r endDate];
|
||||
|
||||
if (jnFirst > jnEnd)
|
||||
if ([endDate compare: firStart] == NSOrderedAscending)
|
||||
// Range ends before first occurrence
|
||||
return nil;
|
||||
|
||||
jnStart = [[_r startDate] julianNumber];
|
||||
interval = [rrule repeatInterval];
|
||||
|
||||
/* if rule is bound, check the bounds */
|
||||
// If rule is bound, check the bounds
|
||||
if (![rrule isInfinite])
|
||||
{
|
||||
NSCalendarDate *until;
|
||||
long jnRuleLast;
|
||||
NSCalendarDate *until, *lastDate;
|
||||
|
||||
until = [rrule untilDate];
|
||||
if (until)
|
||||
{
|
||||
if ([until compare: [_r startDate]] == NSOrderedAscending)
|
||||
return nil;
|
||||
jnRuleLast = [until julianNumber];
|
||||
}
|
||||
lastDate = until;
|
||||
else
|
||||
{
|
||||
jnRuleLast = (interval * [rrule repeatCount] * 7)
|
||||
+ jnFirst;
|
||||
if (jnRuleLast < jnStart)
|
||||
lastDate = [firStart dateByAddingYears: 0 months: 0
|
||||
days: (interval
|
||||
* ([rrule repeatCount] - 1) * 7)];
|
||||
|
||||
if ([lastDate compare: startDate] == NSOrderedAscending)
|
||||
// Range starts after last occurrence
|
||||
return nil;
|
||||
}
|
||||
/* jnStart < jnRuleLast < jnEnd ? */
|
||||
if (jnEnd > jnRuleLast)
|
||||
jnEnd = jnRuleLast;
|
||||
if ([lastDate compare: endDate] == NSOrderedAscending)
|
||||
// Range ends after last occurence; adjust end date
|
||||
endDate = lastDate;
|
||||
}
|
||||
|
||||
startEndCount = (jnEnd - jnStart) + 1;
|
||||
ranges = [NSMutableArray arrayWithCapacity: startEndCount];
|
||||
currentStartDate = [firStart copy];
|
||||
ranges = [NSMutableArray array];
|
||||
byDayMask = [rrule byDayMask];
|
||||
i = 1;
|
||||
if (!byDayMask)
|
||||
{
|
||||
for (i = 0 ; i < startEndCount; i++)
|
||||
while ([currentStartDate compare: endDate] == NSOrderedAscending ||
|
||||
[currentStartDate compare: endDate] == NSOrderedSame)
|
||||
{
|
||||
long jnCurrent;
|
||||
|
||||
jnCurrent = jnStart + i;
|
||||
if (jnCurrent >= jnFirst)
|
||||
if ([startDate compare: currentStartDate] == NSOrderedAscending ||
|
||||
[startDate compare: currentStartDate] == NSOrderedSame)
|
||||
{
|
||||
long jnDiff;
|
||||
|
||||
jnDiff = jnCurrent - jnFirst; /* difference in days */
|
||||
if ((jnDiff % (interval * 7)) == 0)
|
||||
{
|
||||
NSCalendarDate *start, *end;
|
||||
NGCalendarDateRange *r;
|
||||
|
||||
start = [NSCalendarDate dateForJulianNumber: jnCurrent];
|
||||
[start setTimeZone: [firStart timeZone]];
|
||||
start = [start hour: [firStart hourOfDay]
|
||||
minute: [firStart minuteOfHour]
|
||||
second: [firStart secondOfMinute]];
|
||||
end = [start addTimeInterval: [firstRange duration]];
|
||||
r = [NGCalendarDateRange calendarDateRangeWithStartDate: start
|
||||
endDate: end];
|
||||
currentEndDate = [currentStartDate addTimeInterval: [firstRange duration]];
|
||||
r = [NGCalendarDateRange calendarDateRangeWithStartDate: currentStartDate
|
||||
endDate: currentEndDate];
|
||||
if ([_r containsDateRange: r])
|
||||
[ranges addObject: r];
|
||||
}
|
||||
}
|
||||
currentStartDate = [firStart dateByAddingYears: 0
|
||||
months: 0
|
||||
days: (interval * i * 7)];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
long jnFirstWeekStart, weekStartOffset;
|
||||
unsigned dayOfWeek;
|
||||
NGCalendarDateRange *r;
|
||||
|
||||
/* calculate jnFirst's week start - this depends on our setting of week
|
||||
start */
|
||||
weekStartOffset = [self offsetFromSundayForJulianNumber: jnFirst] -
|
||||
[self offsetFromSundayForCurrentWeekStart];
|
||||
|
||||
jnFirstWeekStart = jnFirst - weekStartOffset;
|
||||
|
||||
for (i = 0 ; i < startEndCount; i++)
|
||||
while ([currentStartDate compare: endDate] == NSOrderedAscending ||
|
||||
[currentStartDate compare: endDate] == NSOrderedSame)
|
||||
{
|
||||
long jnCurrent;
|
||||
|
||||
jnCurrent = jnStart + i;
|
||||
if (jnCurrent >= jnFirst)
|
||||
if ([startDate compare: currentStartDate] == NSOrderedAscending ||
|
||||
[startDate compare: currentStartDate] == NSOrderedSame)
|
||||
{
|
||||
long jnDiff;
|
||||
unsigned int days, week;
|
||||
|
||||
/* we need to calculate a difference in weeks */
|
||||
jnDiff = (jnCurrent - jnFirstWeekStart) % 7;
|
||||
if ((jnDiff % interval) == 0)
|
||||
[currentStartDate years:NULL months:NULL days:&days hours:NULL
|
||||
minutes:NULL seconds:NULL sinceDate:firStart];
|
||||
week = days / 7;
|
||||
|
||||
if ((week % interval) == 0)
|
||||
{
|
||||
// Date is in the proper week with respect to the
|
||||
// week interval
|
||||
BOOL isRecurrence = NO;
|
||||
|
||||
if (jnCurrent == jnFirst)
|
||||
{
|
||||
if ([currentStartDate compare: firStart] == NSOrderedSame)
|
||||
// Always add the event of the start date of
|
||||
// the recurring event.
|
||||
isRecurrence = YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
iCalWeekDay weekDay;
|
||||
|
||||
weekDay = [self weekDayForJulianNumber: jnCurrent];
|
||||
isRecurrence = (weekDay & [rrule byDayMask]) ? YES : NO;
|
||||
// Only consider events that matches the day mask.
|
||||
dayOfWeek = ([currentStartDate dayOfWeek]
|
||||
? (unsigned int) 1 << [currentStartDate dayOfWeek]
|
||||
: iCalWeekDaySunday);
|
||||
if (dayOfWeek & [rrule byDayMask])
|
||||
isRecurrence = YES;
|
||||
}
|
||||
if (isRecurrence)
|
||||
{
|
||||
NSCalendarDate *start, *end;
|
||||
NGCalendarDateRange *r;
|
||||
|
||||
start = [NSCalendarDate dateForJulianNumber: jnCurrent];
|
||||
[start setTimeZone: [firStart timeZone]];
|
||||
start = [start hour: [firStart hourOfDay]
|
||||
minute: [firStart minuteOfHour]
|
||||
second: [firStart secondOfMinute]];
|
||||
end = [start addTimeInterval: [firstRange duration]];
|
||||
r = [NGCalendarDateRange calendarDateRangeWithStartDate: start
|
||||
endDate: end];
|
||||
currentEndDate = [currentStartDate addTimeInterval: [firstRange duration]];
|
||||
r = [NGCalendarDateRange calendarDateRangeWithStartDate: currentStartDate
|
||||
endDate: currentEndDate];
|
||||
if ([_r containsDateRange: r])
|
||||
[ranges addObject: r];
|
||||
}
|
||||
}
|
||||
}
|
||||
currentStartDate = [currentStartDate dateByAddingYears: 0
|
||||
months: 0
|
||||
days: 1];
|
||||
}
|
||||
}
|
||||
|
||||
return ranges;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue