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>
|
2008-12-17 Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||||
|
|
||||||
* SoObjects/SOGo/SOGoParentFolder.m ([SOGoParentFolder
|
* SoObjects/SOGo/SOGoParentFolder.m ([SOGoParentFolder
|
||||||
|
|
|
@ -43,87 +43,78 @@
|
||||||
recurrenceRangesWithinCalendarDateRange: (NGCalendarDateRange *) _r
|
recurrenceRangesWithinCalendarDateRange: (NGCalendarDateRange *) _r
|
||||||
{
|
{
|
||||||
NSMutableArray *ranges;
|
NSMutableArray *ranges;
|
||||||
NSCalendarDate *firStart;
|
NSCalendarDate *firStart, *startDate, *endDate, *currentStartDate, *currentEndDate;
|
||||||
long i, jnFirst, jnStart, jnEnd, startEndCount;
|
long i;
|
||||||
unsigned interval;
|
unsigned interval;
|
||||||
|
|
||||||
firStart = [firstRange startDate];
|
firStart = [firstRange startDate];
|
||||||
jnFirst = [firStart julianNumber];
|
startDate = [_r startDate];
|
||||||
jnEnd = [[_r endDate] julianNumber];
|
endDate = [_r endDate];
|
||||||
|
|
||||||
if (jnFirst > jnEnd)
|
if ([endDate compare: firStart] == NSOrderedAscending)
|
||||||
|
// Range ends before first occurrence
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
jnStart = [[_r startDate] julianNumber];
|
|
||||||
interval = [rrule repeatInterval];
|
interval = [rrule repeatInterval];
|
||||||
|
|
||||||
/* if rule is bound, check the bounds */
|
// If rule is bound, check the bounds
|
||||||
if (![rrule isInfinite])
|
if (![rrule isInfinite])
|
||||||
{
|
{
|
||||||
NSCalendarDate *until;
|
NSCalendarDate *until, *lastDate;
|
||||||
long jnRuleLast;
|
|
||||||
|
|
||||||
until = [rrule untilDate];
|
until = [rrule untilDate];
|
||||||
if (until)
|
if (until)
|
||||||
{
|
lastDate = until;
|
||||||
if ([until compare: [_r startDate]] == NSOrderedAscending)
|
else
|
||||||
return nil;
|
lastDate = [firStart dateByAddingYears: 0 months: 0
|
||||||
jnRuleLast = [until julianNumber];
|
days: (interval
|
||||||
}
|
* ([rrule repeatCount] - 1))];
|
||||||
else
|
|
||||||
{
|
if ([lastDate compare: startDate] == NSOrderedAscending)
|
||||||
jnRuleLast = (interval * [rrule repeatCount])
|
// Range starts after last occurrence
|
||||||
+ jnFirst - 1;
|
return nil;
|
||||||
if (jnRuleLast < jnStart)
|
|
||||||
return nil;
|
if ([lastDate compare: endDate] == NSOrderedAscending)
|
||||||
}
|
// Range ends after last occurence; adjust end date
|
||||||
/* jnStart < jnRuleLast < jnEnd ? */
|
endDate = lastDate;
|
||||||
if (jnEnd > jnRuleLast)
|
|
||||||
jnEnd = jnRuleLast;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
startEndCount = (jnEnd - jnStart) + 1;
|
currentStartDate = [firStart copy];
|
||||||
ranges = [NSMutableArray arrayWithCapacity:startEndCount];
|
ranges = [NSMutableArray array];
|
||||||
for (i = 0 ; i < startEndCount; i++)
|
i = 1;
|
||||||
|
|
||||||
|
while ([currentStartDate compare: endDate] == NSOrderedAscending ||
|
||||||
|
[currentStartDate compare: endDate] == NSOrderedSame)
|
||||||
{
|
{
|
||||||
long jnCurrent;
|
if ([startDate compare: currentStartDate] == NSOrderedAscending ||
|
||||||
|
[startDate compare: currentStartDate] == NSOrderedSame)
|
||||||
jnCurrent = jnStart + i;
|
|
||||||
if (jnCurrent >= jnFirst)
|
|
||||||
{
|
{
|
||||||
long jnTest;
|
BOOL wrongDay = NO;
|
||||||
|
unsigned int mask;
|
||||||
jnTest = jnCurrent - jnFirst;
|
NGCalendarDateRange *r;
|
||||||
if ((jnTest % interval) == 0)
|
|
||||||
|
if ([rrule byDayMask])
|
||||||
{
|
{
|
||||||
NSCalendarDate *start, *end;
|
mask = ([currentStartDate dayOfWeek]
|
||||||
NGCalendarDateRange *r;
|
? (unsigned int) 1 << ([currentStartDate dayOfWeek])
|
||||||
unsigned int mask;
|
: iCalWeekDaySunday);
|
||||||
|
if (([rrule byDayMask] & mask) != mask)
|
||||||
|
wrongDay = YES;
|
||||||
|
}
|
||||||
|
|
||||||
start = [NSCalendarDate dateForJulianNumber:jnCurrent];
|
if (wrongDay == NO)
|
||||||
[start setTimeZone: [firStart timeZone]];
|
{
|
||||||
start = [start hour: [firStart hourOfDay]
|
currentEndDate = [currentStartDate addTimeInterval: [firstRange duration]];
|
||||||
minute: [firStart minuteOfHour]
|
r = [NGCalendarDateRange calendarDateRangeWithStartDate: currentStartDate
|
||||||
second: [firStart secondOfMinute]];
|
endDate: currentEndDate];
|
||||||
end = [start addTimeInterval: [firstRange duration]];
|
if ([_r containsDateRange: r])
|
||||||
|
[ranges addObject: r];
|
||||||
// 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])
|
|
||||||
: iCalWeekDaySunday);
|
|
||||||
if (([rrule byDayMask]&mask) != mask) continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
r = [NGCalendarDateRange calendarDateRangeWithStartDate:start
|
|
||||||
endDate:end];
|
|
||||||
if ([_r containsDateRange:r])
|
|
||||||
[ranges addObject:r];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentStartDate = [firStart dateByAddingYears: 0 months: 0
|
||||||
|
days: (interval * i)];
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
return ranges;
|
return ranges;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,140 +48,122 @@
|
||||||
*/
|
*/
|
||||||
@implementation iCalWeeklyRecurrenceCalculator
|
@implementation iCalWeeklyRecurrenceCalculator
|
||||||
|
|
||||||
- (NSArray *)
|
- (NSArray *) recurrenceRangesWithinCalendarDateRange: (NGCalendarDateRange *) _r
|
||||||
recurrenceRangesWithinCalendarDateRange: (NGCalendarDateRange *) _r
|
|
||||||
{
|
{
|
||||||
NSMutableArray *ranges;
|
NSMutableArray *ranges;
|
||||||
NSCalendarDate *firStart;
|
NSCalendarDate *firStart, *startDate, *endDate, *currentStartDate, *currentEndDate;
|
||||||
long i, jnFirst, jnStart, jnEnd, startEndCount;
|
long i;
|
||||||
unsigned interval, byDayMask;
|
unsigned interval, byDayMask;
|
||||||
|
|
||||||
firStart = [firstRange startDate];
|
firStart = [firstRange startDate];
|
||||||
jnFirst = [firStart julianNumber];
|
startDate = [_r startDate];
|
||||||
jnEnd = [[_r endDate] julianNumber];
|
endDate = [_r endDate];
|
||||||
|
|
||||||
if (jnFirst > jnEnd)
|
if ([endDate compare: firStart] == NSOrderedAscending)
|
||||||
|
// Range ends before first occurrence
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
jnStart = [[_r startDate] julianNumber];
|
|
||||||
interval = [rrule repeatInterval];
|
interval = [rrule repeatInterval];
|
||||||
|
|
||||||
/* if rule is bound, check the bounds */
|
// If rule is bound, check the bounds
|
||||||
if (![rrule isInfinite])
|
if (![rrule isInfinite])
|
||||||
{
|
{
|
||||||
NSCalendarDate *until;
|
NSCalendarDate *until, *lastDate;
|
||||||
long jnRuleLast;
|
|
||||||
|
|
||||||
until = [rrule untilDate];
|
until = [rrule untilDate];
|
||||||
if (until)
|
if (until)
|
||||||
{
|
lastDate = until;
|
||||||
if ([until compare: [_r startDate]] == NSOrderedAscending)
|
|
||||||
return nil;
|
|
||||||
jnRuleLast = [until julianNumber];
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
lastDate = [firStart dateByAddingYears: 0 months: 0
|
||||||
jnRuleLast = (interval * [rrule repeatCount] * 7)
|
days: (interval
|
||||||
+ jnFirst;
|
* ([rrule repeatCount] - 1) * 7)];
|
||||||
if (jnRuleLast < jnStart)
|
|
||||||
return nil;
|
if ([lastDate compare: startDate] == NSOrderedAscending)
|
||||||
}
|
// Range starts after last occurrence
|
||||||
/* jnStart < jnRuleLast < jnEnd ? */
|
return nil;
|
||||||
if (jnEnd > jnRuleLast)
|
if ([lastDate compare: endDate] == NSOrderedAscending)
|
||||||
jnEnd = jnRuleLast;
|
// Range ends after last occurence; adjust end date
|
||||||
|
endDate = lastDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
startEndCount = (jnEnd - jnStart) + 1;
|
currentStartDate = [firStart copy];
|
||||||
ranges = [NSMutableArray arrayWithCapacity: startEndCount];
|
ranges = [NSMutableArray array];
|
||||||
byDayMask = [rrule byDayMask];
|
byDayMask = [rrule byDayMask];
|
||||||
|
i = 1;
|
||||||
if (!byDayMask)
|
if (!byDayMask)
|
||||||
{
|
{
|
||||||
for (i = 0 ; i < startEndCount; i++)
|
while ([currentStartDate compare: endDate] == NSOrderedAscending ||
|
||||||
|
[currentStartDate compare: endDate] == NSOrderedSame)
|
||||||
{
|
{
|
||||||
long jnCurrent;
|
if ([startDate compare: currentStartDate] == NSOrderedAscending ||
|
||||||
|
[startDate compare: currentStartDate] == NSOrderedSame)
|
||||||
jnCurrent = jnStart + i;
|
|
||||||
if (jnCurrent >= jnFirst)
|
|
||||||
{
|
{
|
||||||
long jnDiff;
|
NGCalendarDateRange *r;
|
||||||
|
|
||||||
jnDiff = jnCurrent - jnFirst; /* difference in days */
|
currentEndDate = [currentStartDate addTimeInterval: [firstRange duration]];
|
||||||
if ((jnDiff % (interval * 7)) == 0)
|
r = [NGCalendarDateRange calendarDateRangeWithStartDate: currentStartDate
|
||||||
{
|
endDate: currentEndDate];
|
||||||
NSCalendarDate *start, *end;
|
if ([_r containsDateRange: r])
|
||||||
NGCalendarDateRange *r;
|
[ranges addObject: r];
|
||||||
|
}
|
||||||
start = [NSCalendarDate dateForJulianNumber: jnCurrent];
|
currentStartDate = [firStart dateByAddingYears: 0
|
||||||
[start setTimeZone: [firStart timeZone]];
|
months: 0
|
||||||
start = [start hour: [firStart hourOfDay]
|
days: (interval * i * 7)];
|
||||||
minute: [firStart minuteOfHour]
|
i++;
|
||||||
second: [firStart secondOfMinute]];
|
|
||||||
end = [start addTimeInterval: [firstRange duration]];
|
|
||||||
r = [NGCalendarDateRange calendarDateRangeWithStartDate: start
|
|
||||||
endDate: end];
|
|
||||||
if ([_r containsDateRange: r])
|
|
||||||
[ranges addObject: r];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
long jnFirstWeekStart, weekStartOffset;
|
unsigned dayOfWeek;
|
||||||
|
NGCalendarDateRange *r;
|
||||||
/* calculate jnFirst's week start - this depends on our setting of week
|
|
||||||
start */
|
while ([currentStartDate compare: endDate] == NSOrderedAscending ||
|
||||||
weekStartOffset = [self offsetFromSundayForJulianNumber: jnFirst] -
|
[currentStartDate compare: endDate] == NSOrderedSame)
|
||||||
[self offsetFromSundayForCurrentWeekStart];
|
|
||||||
|
|
||||||
jnFirstWeekStart = jnFirst - weekStartOffset;
|
|
||||||
|
|
||||||
for (i = 0 ; i < startEndCount; i++)
|
|
||||||
{
|
{
|
||||||
long jnCurrent;
|
if ([startDate compare: currentStartDate] == NSOrderedAscending ||
|
||||||
|
[startDate compare: currentStartDate] == NSOrderedSame)
|
||||||
jnCurrent = jnStart + i;
|
|
||||||
if (jnCurrent >= jnFirst)
|
|
||||||
{
|
{
|
||||||
long jnDiff;
|
unsigned int days, week;
|
||||||
|
|
||||||
/* we need to calculate a difference in weeks */
|
[currentStartDate years:NULL months:NULL days:&days hours:NULL
|
||||||
jnDiff = (jnCurrent - jnFirstWeekStart) % 7;
|
minutes:NULL seconds:NULL sinceDate:firStart];
|
||||||
if ((jnDiff % interval) == 0)
|
week = days / 7;
|
||||||
|
|
||||||
|
if ((week % interval) == 0)
|
||||||
{
|
{
|
||||||
|
// Date is in the proper week with respect to the
|
||||||
|
// week interval
|
||||||
BOOL isRecurrence = NO;
|
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
|
||||||
{
|
{
|
||||||
isRecurrence = YES;
|
// Only consider events that matches the day mask.
|
||||||
|
dayOfWeek = ([currentStartDate dayOfWeek]
|
||||||
|
? (unsigned int) 1 << [currentStartDate dayOfWeek]
|
||||||
|
: iCalWeekDaySunday);
|
||||||
|
if (dayOfWeek & [rrule byDayMask])
|
||||||
|
isRecurrence = YES;
|
||||||
}
|
}
|
||||||
else
|
if (isRecurrence)
|
||||||
{
|
{
|
||||||
iCalWeekDay weekDay;
|
currentEndDate = [currentStartDate addTimeInterval: [firstRange duration]];
|
||||||
|
r = [NGCalendarDateRange calendarDateRangeWithStartDate: currentStartDate
|
||||||
weekDay = [self weekDayForJulianNumber: jnCurrent];
|
endDate: currentEndDate];
|
||||||
isRecurrence = (weekDay & [rrule byDayMask]) ? YES : NO;
|
|
||||||
}
|
|
||||||
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];
|
|
||||||
if ([_r containsDateRange: r])
|
if ([_r containsDateRange: r])
|
||||||
[ranges addObject: r];
|
[ranges addObject: r];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
currentStartDate = [currentStartDate dateByAddingYears: 0
|
||||||
|
months: 0
|
||||||
|
days: 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ranges;
|
return ranges;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue