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

@ -3,17 +3,17 @@
Copyright (C) 2006-2010 Inverse inc. Copyright (C) 2006-2010 Inverse inc.
This file is part of SOPE. This file is part of SOPE.
SOPE is free software; you can redistribute it and/or modify it under SOPE is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any Free Software Foundation; either version 2, or (at your option) any
later version. later version.
SOPE is distributed in the hope that it will be useful, but WITHOUT ANY SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details. License for more details.
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with SOPE; see the file COPYING. If not, write to the License along with SOPE; see the file COPYING. If not, write to the
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
@ -38,20 +38,20 @@
@implementation iCalDailyRecurrenceCalculator @implementation iCalDailyRecurrenceCalculator
/** /**
* TODO : Unsupported conditions for DAILY recurrences : * TODO : Unsupported conditions for DAILY recurrences :
* *
* BYYEAR * BYYEAR
* BYYEARDAY * BYYEARDAY
* BYWEEKNO * BYWEEKNO
* BYMONTH * BYMONTH
* BYMONTHDAY * BYMONTHDAY
* BYHOUR * BYHOUR
* BYMINUTE * BYMINUTE
* *
* There's no GUI to defined such conditions, so there's no * There's no GUI to defined such conditions, so there's no
* problem for now. * problem for now.
*/ */
- (NSArray *) - (NSArray *)
recurrenceRangesWithinCalendarDateRange: (NGCalendarDateRange *) _r recurrenceRangesWithinCalendarDateRange: (NGCalendarDateRange *) _r
{ {
@ -66,48 +66,48 @@
endDate = [_r endDate]; endDate = [_r endDate];
dayMask = nil; dayMask = nil;
repeatCount = 0; repeatCount = 0;
if ([endDate compare: firStart] == NSOrderedAscending) if ([endDate compare: firStart] == NSOrderedAscending)
// Range ends before first occurrence // Range ends before first occurrence
return nil; return nil;
interval = [rrule repeatInterval]; interval = [rrule repeatInterval];
if ([[rrule byDay] length]) if ([[rrule byDay] length])
dayMask = [rrule byDayMask]; dayMask = [rrule byDayMask];
// If rule is bound, check the bounds // If rule is bound, check the bounds
if (![rrule isInfinite]) if (![rrule isInfinite])
{ {
NSCalendarDate *until, *lastDate; NSCalendarDate *until, *lastDate;
lastDate = nil; lastDate = nil;
until = [rrule untilDate]; until = [rrule untilDate];
if (until) if (until)
{ {
lastDate = until; lastDate = until;
} }
else else
{ {
repeatCount = [rrule repeatCount]; repeatCount = [rrule repeatCount];
if (dayMask == nil) if (dayMask == nil)
// If there's no day mask, we can compute the date of the last // If there's no day mask, we can compute the date of the last
// occurrence of the recurrent rule. // occurrence of the recurrent rule.
lastDate = [firStart dateByAddingYears: 0 months: 0 lastDate = [firStart dateByAddingYears: 0 months: 0
days: (interval days: (interval
* (repeatCount - 1))]; * (repeatCount - 1))];
} }
if (lastDate != nil) if (lastDate != nil)
{ {
if ([lastDate compare: startDate] == NSOrderedAscending) if ([lastDate compare: startDate] == NSOrderedAscending)
// Range starts after last occurrence // Range starts after last occurrence
return nil; return nil;
if ([lastDate compare: endDate] == NSOrderedAscending) if ([lastDate compare: endDate] == NSOrderedAscending)
// Range ends after last occurence; adjust end date // Range ends after last occurence; adjust end date
endDate = lastDate; endDate = lastDate;
} }
} }
currentStartDate = [firStart copy]; currentStartDate = [firStart copy];
@ -115,9 +115,9 @@
ranges = [NSMutableArray array]; ranges = [NSMutableArray array];
i = 1; i = 1;
count = 0; count = 0;
while ([currentStartDate compare: endDate] == NSOrderedAscending || while ([currentStartDate compare: endDate] == NSOrderedAscending ||
[currentStartDate compare: endDate] == NSOrderedSame) [currentStartDate compare: endDate] == NSOrderedSame)
{ {
BOOL wrongDay, isFirStart; BOOL wrongDay, isFirStart;
@ -125,26 +125,26 @@
isFirStart = NO; isFirStart = NO;
if (i == 1) if (i == 1)
{ {
isFirStart = YES; isFirStart = YES;
count++; count++;
} }
else if (repeatCount > 0 && dayMask) else if (repeatCount > 0 && dayMask)
{ {
// If the rule count is defined, stop once the count is reached. // If the rule count is defined, stop once the count is reached.
if ([dayMask occursOnDay: [currentStartDate dayOfWeek]]) if ([dayMask occursOnDay: [currentStartDate dayOfWeek]])
count++; count++;
else else
wrongDay = YES; wrongDay = YES;
if (count > repeatCount) if (count > repeatCount)
break; break;
} }
if (wrongDay == NO) if (wrongDay == NO)
{ {
currentEndDate = [currentStartDate addTimeInterval: [firstRange duration]]; currentEndDate = [currentStartDate addTimeInterval: [firstRange duration]];
if ([startDate compare: currentStartDate] == NSOrderedAscending || if ([startDate compare: currentStartDate] == NSOrderedAscending ||
[startDate compare: currentStartDate] == NSOrderedSame || [startDate compare: currentStartDate] == NSOrderedSame ||
[startDate compare: currentEndDate] == NSOrderedAscending) [startDate compare: currentEndDate] == NSOrderedAscending)
{ {
@ -155,7 +155,7 @@
if (![dayMask occursOnDay: [currentStartDate dayOfWeek]]) if (![dayMask occursOnDay: [currentStartDate dayOfWeek]])
wrongDay = YES; wrongDay = YES;
} }
if (isFirStart == YES || wrongDay == NO) if (isFirStart == YES || wrongDay == NO)
{ {
r = [NGCalendarDateRange calendarDateRangeWithStartDate: currentStartDate r = [NGCalendarDateRange calendarDateRangeWithStartDate: currentStartDate
@ -163,20 +163,20 @@
[ranges addObject: r]; [ranges addObject: r];
} }
} }
} }
currentStartDate = [firStart dateByAddingYears: 0 months: 0 currentStartDate = [firStart dateByAddingYears: 0 months: 0
days: (interval * i)]; days: (interval * i)];
if (repeatCount > 0 && count == repeatCount) if (repeatCount > 0 && count == repeatCount)
// The count variable is only usefull when a BYDAY constraint is // The count variable is only usefull when a BYDAY constraint is
// defined; when there's no BYDAY constraint, the endDate has been // defined; when there's no BYDAY constraint, the endDate has been
// adjusted to match the repeat count, if defined. // adjusted to match the repeat count, if defined.
break; break;
i++; i++;
} }
return ranges; return ranges;
} }
@ -185,27 +185,27 @@
NSCalendarDate *firStart, *lastInstanceStartDate; NSCalendarDate *firStart, *lastInstanceStartDate;
NGCalendarDateRange *r; NGCalendarDateRange *r;
NSArray *instances; NSArray *instances;
lastInstanceStartDate = nil; lastInstanceStartDate = nil;
if ([rrule repeatCount] > 0) if ([rrule repeatCount] > 0)
{ {
firStart = [firstRange startDate]; firStart = [firstRange startDate];
if ([rrule hasByMask]) if ([rrule hasByMask])
{ {
// Must perform the complete calculation // Must perform the complete calculation
r = [NGCalendarDateRange calendarDateRangeWithStartDate: firStart r = [NGCalendarDateRange calendarDateRangeWithStartDate: firStart
endDate: [NSCalendarDate distantFuture]]; endDate: [NSCalendarDate distantFuture]];
instances = [self recurrenceRangesWithinCalendarDateRange: r]; instances = [self recurrenceRangesWithinCalendarDateRange: r];
if ([instances count]) if ([instances count])
lastInstanceStartDate = [(NGCalendarDateRange *)[instances lastObject] startDate]; lastInstanceStartDate = [(NGCalendarDateRange *)[instances lastObject] startDate];
} }
else else
{ {
// No BYxxx mask // No BYxxx mask
lastInstanceStartDate = [firStart dateByAddingYears: 0 months: 0 lastInstanceStartDate = [firStart dateByAddingYears: 0 months: 0
days: ([rrule repeatInterval] days: ([rrule repeatInterval]
* ([rrule repeatCount] - 1))]; * ([rrule repeatCount] - 1))];
} }
} }
else else
lastInstanceStartDate = [super lastInstanceStartDate]; lastInstanceStartDate = [super lastInstanceStartDate];

View File

@ -1,19 +1,19 @@
/* /*
Copyright (C) 2004-2005 SKYRIX Software AG Copyright (C) 2004-2005 SKYRIX Software AG
Copyright (C) 2006-2012 Inverse inc. Copyright (C) 2006-2012 Inverse inc.
This file is part of SOPE. This file is part of SOPE.
SOPE is free software; you can redistribute it and/or modify it under SOPE is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any Free Software Foundation; either version 2, or (at your option) any
later version. later version.
SOPE is distributed in the hope that it will be useful, but WITHOUT ANY SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details. License for more details.
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with SOPE; see the file COPYING. If not, write to the License along with SOPE; see the file COPYING. If not, write to the
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
@ -21,6 +21,7 @@
*/ */
#import <NGExtensions/NSCalendarDate+misc.h> #import <NGExtensions/NSCalendarDate+misc.h>
#import <NGExtensions/NSObject+Logs.h>
#import "iCalRecurrenceCalculator.h" #import "iCalRecurrenceCalculator.h"
@ -38,28 +39,28 @@
- (unsigned) offsetFromSundayForJulianNumber: (long) _jn; - (unsigned) offsetFromSundayForJulianNumber: (long) _jn;
- (unsigned) offsetFromSundayForWeekDay: (iCalWeekDay) _weekDay; - (unsigned) offsetFromSundayForWeekDay: (iCalWeekDay) _weekDay;
- (unsigned) offsetFromSundayForCurrentWeekStart; - (unsigned) offsetFromSundayForCurrentWeekStart;
- (iCalWeekDay) weekDayForJulianNumber: (long) _jn; - (iCalWeekDay) weekDayForJulianNumber: (long) _jn;
@end @end
@implementation iCalWeeklyRecurrenceCalculator @implementation iCalWeeklyRecurrenceCalculator
/** /**
* TODO : Unsupported conditions for WEEKLY recurrences : * TODO : Unsupported conditions for WEEKLY recurrences :
* *
* BYYEAR * BYYEAR
* BYYEARDAY * BYYEARDAY
* BYWEEKNO * BYWEEKNO
* BYMONTH * BYMONTH
* BYMONTHDAY * BYMONTHDAY
* BYHOUR * BYHOUR
* BYMINUTE * BYMINUTE
* WKST * WKST
* *
* There's no GUI to defined such conditions, so there's no * There's no GUI to defined such conditions, so there's no
* problem for now. * problem for now.
*/ */
- (NSArray *) recurrenceRangesWithinCalendarDateRange: (NGCalendarDateRange *) _r - (NSArray *) recurrenceRangesWithinCalendarDateRange: (NGCalendarDateRange *) _r
{ {
NSMutableArray *ranges; NSMutableArray *ranges;
@ -68,6 +69,8 @@
unsigned interval; unsigned interval;
iCalByDayMask *dayMask; iCalByDayMask *dayMask;
[self logWithFormat: @"Weekly %@", rrule];
firStart = [firstRange startDate]; firStart = [firstRange startDate];
startDate = [_r startDate]; startDate = [_r startDate];
endDate = [_r endDate]; endDate = [_r endDate];
@ -77,9 +80,9 @@
if ([endDate compare: firStart] == NSOrderedAscending) if ([endDate compare: firStart] == NSOrderedAscending)
// Range ends before first occurrence // Range ends before first occurrence
return nil; return nil;
interval = [rrule repeatInterval]; interval = [rrule repeatInterval];
if ([[rrule byDay] length]) if ([[rrule byDay] length])
dayMask = [rrule byDayMask]; dayMask = [rrule byDayMask];
@ -87,33 +90,33 @@
if (![rrule isInfinite]) if (![rrule isInfinite])
{ {
NSCalendarDate *until, *lastDate; NSCalendarDate *until, *lastDate;
lastDate = nil; lastDate = nil;
until = [rrule untilDate]; until = [rrule untilDate];
if (until) if (until)
lastDate = until; lastDate = until;
else else
{ {
repeatCount = [rrule repeatCount]; repeatCount = [rrule repeatCount];
if (dayMask == nil) if (dayMask == nil)
// When there's no BYxxx mask, we can find the date of the last // When there's no BYxxx mask, we can find the date of the last
// occurrence. // occurrence.
lastDate = [firStart dateByAddingYears: 0 months: 0 lastDate = [firStart dateByAddingYears: 0 months: 0
days: (interval days: (interval
* (repeatCount - 1) * 7)]; * (repeatCount - 1) * 7)];
} }
if (lastDate != nil) if (lastDate != nil)
{ {
if ([lastDate compare: startDate] == NSOrderedAscending) if ([lastDate compare: startDate] == NSOrderedAscending)
// Range starts after last occurrence // Range starts after last occurrence
return nil; return nil;
if ([lastDate compare: endDate] == NSOrderedAscending) if ([lastDate compare: endDate] == NSOrderedAscending)
// Range ends after last occurence; adjust end date // Range ends after last occurence; adjust end date
endDate = lastDate; endDate = lastDate;
} }
} }
currentStartDate = [firStart copy]; currentStartDate = [firStart copy];
[currentStartDate autorelease]; [currentStartDate autorelease];
ranges = [NSMutableArray array]; ranges = [NSMutableArray array];
@ -123,74 +126,77 @@
{ {
i = 0; i = 0;
while ([currentStartDate compare: endDate] == NSOrderedAscending || while ([currentStartDate compare: endDate] == NSOrderedAscending ||
[currentStartDate compare: endDate] == NSOrderedSame) [currentStartDate compare: endDate] == NSOrderedSame)
{ {
currentEndDate = [currentStartDate addTimeInterval: [firstRange duration]]; currentEndDate = [currentStartDate addTimeInterval: [firstRange duration]];
if ([startDate compare: currentStartDate] == NSOrderedAscending || if ([startDate compare: currentStartDate] == NSOrderedAscending ||
[startDate compare: currentStartDate] == NSOrderedSame || [startDate compare: currentStartDate] == NSOrderedSame ||
[startDate compare: currentEndDate] == NSOrderedAscending) [startDate compare: currentEndDate] == NSOrderedAscending)
{ {
NGCalendarDateRange *r; NGCalendarDateRange *r;
r = [NGCalendarDateRange calendarDateRangeWithStartDate: currentStartDate r = [NGCalendarDateRange calendarDateRangeWithStartDate: currentStartDate
endDate: currentEndDate]; endDate: currentEndDate];
[ranges addObject: r]; [ranges addObject: r];
} }
i++; i++;
currentStartDate = [firStart dateByAddingYears: 0 currentStartDate = [firStart dateByAddingYears: 0
months: 0 months: 0
days: (interval * i * 7)]; days: (interval * i * 7)];
} }
} }
else else
{ {
NGCalendarDateRange *r; NGCalendarDateRange *r;
i = [currentStartDate dayOfWeek]; // Set the first day of the week as Sunday and ignore WKST i = [currentStartDate dayOfWeek]; // Set the first day of the week as Sunday and ignore WKST
while ([currentStartDate compare: endDate] == NSOrderedAscending || while ([currentStartDate compare: endDate] == NSOrderedAscending ||
[currentStartDate compare: endDate] == NSOrderedSame) [currentStartDate compare: endDate] == NSOrderedSame)
{ {
BOOL isRecurrence = NO; BOOL isRecurrence = NO;
NSInteger week; NSInteger week;
if (repeatCount > 0 || if (repeatCount > 0 ||
[startDate compare: currentStartDate] == NSOrderedAscending || [startDate compare: currentStartDate] == NSOrderedAscending ||
[startDate compare: currentStartDate] == NSOrderedSame) [startDate compare: currentStartDate] == NSOrderedSame)
{ {
// If the rule count is defined, stop once the count is reached. // If the rule count is defined, stop once the count is reached.
if ([currentStartDate compare: firStart] == NSOrderedSame) if ([currentStartDate compare: firStart] == NSOrderedSame)
{ {
// Always add the start date of the recurring event if within // Always add the start date of the recurring event if within
// the lookup range. // the lookup range.
isRecurrence = YES; isRecurrence = YES;
} }
else else
{ {
week = i / 7; week = i / 7;
if ((week % interval) == 0 &&
[dayMask occursOnDay: [currentStartDate dayOfWeek]])
isRecurrence = YES;
}
if (isRecurrence) if ((week % interval) == 0 &&
{ [dayMask occursOnDay: [currentStartDate dayOfWeek]])
count++; isRecurrence = YES;
if (repeatCount > 0 && count > repeatCount) }
break;
currentEndDate = [currentStartDate addTimeInterval: [firstRange duration]];
r = [NGCalendarDateRange calendarDateRangeWithStartDate: currentStartDate
endDate: currentEndDate];
if ([_r doesIntersectWithDateRange: r]) if (isRecurrence)
[ranges addObject: r]; {
} count++;
} if (repeatCount > 0 && count > repeatCount)
currentStartDate = [currentStartDate dateByAddingYears: 0 break;
months: 0 currentEndDate = [currentStartDate addTimeInterval: [firstRange duration]];
days: 1]; r = [NGCalendarDateRange calendarDateRangeWithStartDate: currentStartDate
i++; endDate: currentEndDate];
}
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; return ranges;
@ -207,10 +213,10 @@
{ {
firStart = [firstRange startDate]; firStart = [firstRange startDate];
r = [NGCalendarDateRange calendarDateRangeWithStartDate: firStart r = [NGCalendarDateRange calendarDateRangeWithStartDate: firStart
endDate: [NSCalendarDate distantFuture]]; endDate: [NSCalendarDate distantFuture]];
instances = [self recurrenceRangesWithinCalendarDateRange: r]; instances = [self recurrenceRangesWithinCalendarDateRange: r];
if ([instances count]) if ([instances count])
lastInstanceStartDate = [(NGCalendarDateRange *)[instances lastObject] startDate]; lastInstanceStartDate = [(NGCalendarDateRange *)[instances lastObject] startDate];
} }
else else
lastInstanceStartDate = [super lastInstanceStartDate]; lastInstanceStartDate = [super lastInstanceStartDate];