Untabify + indent

pull/225/head
Francis Lachapelle 2016-11-03 16:02:51 -04:00
parent e6b129c8eb
commit aff6a8b7c9
2 changed files with 195 additions and 189 deletions

View File

@ -38,20 +38,20 @@
@implementation iCalDailyRecurrenceCalculator
/**
* TODO : Unsupported conditions for DAILY recurrences :
*
* BYYEAR
* BYYEARDAY
* BYWEEKNO
* BYMONTH
* BYMONTHDAY
* BYHOUR
* BYMINUTE
*
* There's no GUI to defined such conditions, so there's no
* problem for now.
*/
/**
* TODO : Unsupported conditions for DAILY recurrences :
*
* BYYEAR
* BYYEARDAY
* BYWEEKNO
* BYMONTH
* BYMONTHDAY
* BYHOUR
* BYMINUTE
*
* There's no GUI to defined such conditions, so there's no
* problem for now.
*/
- (NSArray *)
recurrenceRangesWithinCalendarDateRange: (NGCalendarDateRange *) _r
{
@ -84,30 +84,30 @@
lastDate = nil;
until = [rrule untilDate];
if (until)
{
lastDate = until;
}
{
lastDate = until;
}
else
{
repeatCount = [rrule repeatCount];
if (dayMask == nil)
// If there's no day mask, we can compute the date of the last
// occurrence of the recurrent rule.
lastDate = [firStart dateByAddingYears: 0 months: 0
days: (interval
* (repeatCount - 1))];
}
{
repeatCount = [rrule repeatCount];
if (dayMask == nil)
// If there's no day mask, we can compute the date of the last
// occurrence of the recurrent rule.
lastDate = [firStart dateByAddingYears: 0 months: 0
days: (interval
* (repeatCount - 1))];
}
if (lastDate != nil)
{
if ([lastDate compare: startDate] == NSOrderedAscending)
// Range starts after last occurrence
return nil;
{
if ([lastDate compare: startDate] == NSOrderedAscending)
// Range starts after last occurrence
return nil;
if ([lastDate compare: endDate] == NSOrderedAscending)
// Range ends after last occurence; adjust end date
endDate = lastDate;
}
if ([lastDate compare: endDate] == NSOrderedAscending)
// Range ends after last occurence; adjust end date
endDate = lastDate;
}
}
currentStartDate = [firStart copy];
@ -117,7 +117,7 @@
count = 0;
while ([currentStartDate compare: endDate] == NSOrderedAscending ||
[currentStartDate compare: endDate] == NSOrderedSame)
[currentStartDate compare: endDate] == NSOrderedSame)
{
BOOL wrongDay, isFirStart;
@ -125,26 +125,26 @@
isFirStart = NO;
if (i == 1)
{
isFirStart = YES;
count++;
}
{
isFirStart = YES;
count++;
}
else if (repeatCount > 0 && dayMask)
{
// If the rule count is defined, stop once the count is reached.
if ([dayMask occursOnDay: [currentStartDate dayOfWeek]])
count++;
else
wrongDay = YES;
{
// If the rule count is defined, stop once the count is reached.
if ([dayMask occursOnDay: [currentStartDate dayOfWeek]])
count++;
else
wrongDay = YES;
if (count > repeatCount)
break;
}
if (count > repeatCount)
break;
}
if (wrongDay == NO)
{
currentEndDate = [currentStartDate addTimeInterval: [firstRange duration]];
if ([startDate compare: currentStartDate] == NSOrderedAscending ||
if ([startDate compare: currentStartDate] == NSOrderedAscending ||
[startDate compare: currentStartDate] == NSOrderedSame ||
[startDate compare: currentEndDate] == NSOrderedAscending)
{
@ -163,16 +163,16 @@
[ranges addObject: r];
}
}
}
}
currentStartDate = [firStart dateByAddingYears: 0 months: 0
days: (interval * i)];
days: (interval * i)];
if (repeatCount > 0 && count == repeatCount)
// The count variable is only usefull when a BYDAY constraint is
// defined; when there's no BYDAY constraint, the endDate has been
// adjusted to match the repeat count, if defined.
break;
// The count variable is only usefull when a BYDAY constraint is
// defined; when there's no BYDAY constraint, the endDate has been
// adjusted to match the repeat count, if defined.
break;
i++;
}
@ -191,21 +191,21 @@
{
firStart = [firstRange startDate];
if ([rrule hasByMask])
{
// Must perform the complete calculation
r = [NGCalendarDateRange calendarDateRangeWithStartDate: firStart
endDate: [NSCalendarDate distantFuture]];
instances = [self recurrenceRangesWithinCalendarDateRange: r];
if ([instances count])
lastInstanceStartDate = [(NGCalendarDateRange *)[instances lastObject] startDate];
}
{
// Must perform the complete calculation
r = [NGCalendarDateRange calendarDateRangeWithStartDate: firStart
endDate: [NSCalendarDate distantFuture]];
instances = [self recurrenceRangesWithinCalendarDateRange: r];
if ([instances count])
lastInstanceStartDate = [(NGCalendarDateRange *)[instances lastObject] startDate];
}
else
{
// No BYxxx mask
lastInstanceStartDate = [firStart dateByAddingYears: 0 months: 0
days: ([rrule repeatInterval]
* ([rrule repeatCount] - 1))];
}
{
// No BYxxx mask
lastInstanceStartDate = [firStart dateByAddingYears: 0 months: 0
days: ([rrule repeatInterval]
* ([rrule repeatCount] - 1))];
}
}
else
lastInstanceStartDate = [super lastInstanceStartDate];

View File

@ -21,6 +21,7 @@
*/
#import <NGExtensions/NSCalendarDate+misc.h>
#import <NGExtensions/NSObject+Logs.h>
#import "iCalRecurrenceCalculator.h"
@ -45,21 +46,21 @@
@implementation iCalWeeklyRecurrenceCalculator
/**
* TODO : Unsupported conditions for WEEKLY recurrences :
*
* BYYEAR
* BYYEARDAY
* BYWEEKNO
* BYMONTH
* BYMONTHDAY
* BYHOUR
* BYMINUTE
* WKST
*
* There's no GUI to defined such conditions, so there's no
* problem for now.
*/
/**
* TODO : Unsupported conditions for WEEKLY recurrences :
*
* BYYEAR
* BYYEARDAY
* BYWEEKNO
* BYMONTH
* BYMONTHDAY
* BYHOUR
* BYMINUTE
* WKST
*
* There's no GUI to defined such conditions, so there's no
* problem for now.
*/
- (NSArray *) recurrenceRangesWithinCalendarDateRange: (NGCalendarDateRange *) _r
{
NSMutableArray *ranges;
@ -68,6 +69,8 @@
unsigned interval;
iCalByDayMask *dayMask;
[self logWithFormat: @"Weekly %@", rrule];
firStart = [firstRange startDate];
startDate = [_r startDate];
endDate = [_r endDate];
@ -91,27 +94,27 @@
lastDate = nil;
until = [rrule untilDate];
if (until)
lastDate = until;
lastDate = until;
else
{
repeatCount = [rrule repeatCount];
if (dayMask == nil)
// When there's no BYxxx mask, we can find the date of the last
// occurrence.
lastDate = [firStart dateByAddingYears: 0 months: 0
days: (interval
* (repeatCount - 1) * 7)];
}
{
repeatCount = [rrule repeatCount];
if (dayMask == nil)
// When there's no BYxxx mask, we can find the date of the last
// occurrence.
lastDate = [firStart dateByAddingYears: 0 months: 0
days: (interval
* (repeatCount - 1) * 7)];
}
if (lastDate != nil)
{
if ([lastDate compare: startDate] == NSOrderedAscending)
// Range starts after last occurrence
return nil;
if ([lastDate compare: endDate] == NSOrderedAscending)
// Range ends after last occurence; adjust end date
endDate = lastDate;
}
{
if ([lastDate compare: startDate] == NSOrderedAscending)
// Range starts after last occurrence
return nil;
if ([lastDate compare: endDate] == NSOrderedAscending)
// Range ends after last occurence; adjust end date
endDate = lastDate;
}
}
currentStartDate = [firStart copy];
@ -123,24 +126,24 @@
{
i = 0;
while ([currentStartDate compare: endDate] == NSOrderedAscending ||
[currentStartDate compare: endDate] == NSOrderedSame)
{
[currentStartDate compare: endDate] == NSOrderedSame)
{
currentEndDate = [currentStartDate addTimeInterval: [firstRange duration]];
if ([startDate compare: currentStartDate] == NSOrderedAscending ||
[startDate compare: currentStartDate] == NSOrderedSame ||
if ([startDate compare: currentStartDate] == NSOrderedAscending ||
[startDate compare: currentStartDate] == NSOrderedSame ||
[startDate compare: currentEndDate] == NSOrderedAscending)
{
NGCalendarDateRange *r;
{
NGCalendarDateRange *r;
r = [NGCalendarDateRange calendarDateRangeWithStartDate: currentStartDate
endDate: currentEndDate];
r = [NGCalendarDateRange calendarDateRangeWithStartDate: currentStartDate
endDate: currentEndDate];
[ranges addObject: r];
}
i++;
currentStartDate = [firStart dateByAddingYears: 0
months: 0
days: (interval * i * 7)];
}
}
i++;
currentStartDate = [firStart dateByAddingYears: 0
months: 0
days: (interval * i * 7)];
}
}
else
{
@ -148,49 +151,52 @@
i = [currentStartDate dayOfWeek]; // Set the first day of the week as Sunday and ignore WKST
while ([currentStartDate compare: endDate] == NSOrderedAscending ||
[currentStartDate compare: endDate] == NSOrderedSame)
{
BOOL isRecurrence = NO;
NSInteger week;
[currentStartDate compare: endDate] == NSOrderedSame)
{
BOOL isRecurrence = NO;
NSInteger week;
if (repeatCount > 0 ||
[startDate compare: currentStartDate] == NSOrderedAscending ||
[startDate compare: currentStartDate] == NSOrderedSame)
{
// If the rule count is defined, stop once the count is reached.
if ([currentStartDate compare: firStart] == NSOrderedSame)
{
// Always add the start date of the recurring event if within
// the lookup range.
isRecurrence = YES;
}
else
{
week = i / 7;
if (repeatCount > 0 ||
[startDate compare: currentStartDate] == NSOrderedAscending ||
[startDate compare: currentStartDate] == NSOrderedSame)
{
// If the rule count is defined, stop once the count is reached.
if ([currentStartDate compare: firStart] == NSOrderedSame)
{
// Always add the start date of the recurring event if within
// the lookup range.
isRecurrence = YES;
}
else
{
week = i / 7;
if ((week % interval) == 0 &&
[dayMask occursOnDay: [currentStartDate dayOfWeek]])
isRecurrence = YES;
}
if ((week % interval) == 0 &&
[dayMask occursOnDay: [currentStartDate dayOfWeek]])
isRecurrence = YES;
}
if (isRecurrence)
{
count++;
if (repeatCount > 0 && count > repeatCount)
break;
currentEndDate = [currentStartDate addTimeInterval: [firstRange duration]];
r = [NGCalendarDateRange calendarDateRangeWithStartDate: currentStartDate
endDate: currentEndDate];
if (isRecurrence)
{
count++;
if (repeatCount > 0 && count > repeatCount)
break;
currentEndDate = [currentStartDate addTimeInterval: [firstRange duration]];
r = [NGCalendarDateRange calendarDateRangeWithStartDate: currentStartDate
endDate: currentEndDate];
if ([_r doesIntersectWithDateRange: r])
[ranges addObject: r];
}
}
currentStartDate = [currentStartDate dateByAddingYears: 0
months: 0
days: 1];
i++;
}
if ([_r doesIntersectWithDateRange: r])
{
[ranges addObject: r];
[self logWithFormat: @"Add range %@ - %@", [r startDate], [r endDate]];
}
}
}
currentStartDate = [currentStartDate dateByAddingYears: 0
months: 0
days: 1];
i++;
}
}
return ranges;
@ -207,10 +213,10 @@
{
firStart = [firstRange startDate];
r = [NGCalendarDateRange calendarDateRangeWithStartDate: firStart
endDate: [NSCalendarDate distantFuture]];
endDate: [NSCalendarDate distantFuture]];
instances = [self recurrenceRangesWithinCalendarDateRange: r];
if ([instances count])
lastInstanceStartDate = [(NGCalendarDateRange *)[instances lastObject] startDate];
lastInstanceStartDate = [(NGCalendarDateRange *)[instances lastObject] startDate];
}
else
lastInstanceStartDate = [super lastInstanceStartDate];