Monotone-Parent: cb36ec3f7d193b795240d0061daae4db88f1c337

Monotone-Revision: 67b80dfcbf50feccf26e6968ff799ca9f51c1b3f

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2011-03-22T20:58:22
Monotone-Branch: ca.inverse.sogo
maint-2.0.2
Wolfgang Sourdeau 2011-03-22 20:58:22 +00:00
parent 9921bba68b
commit f51e037f41
5 changed files with 89 additions and 1 deletions

View File

@ -1,5 +1,12 @@
2011-03-22 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* iCalEvent.m (-firstRecurrenceStartDate): new method that makes
use of the new one below.
* iCalRepeatableEntityObject.m
(-firstRecurrenceStartDateWithEndDate:): new method that returns
the first occurrence of a recurring entity.
* iCalByDayMask.m (-occursOnDay:withWeekOccurrence:): fixed method
to return true only when it is valid to do so...
(-weekDayOccurrences): new method that returns a reference to the

View File

@ -50,7 +50,6 @@
- (NSCalendarDate *) endDate;
- (BOOL) hasEndDate;
- (void) setDuration: (NSString *) _value;
- (NSString *) duration;
- (BOOL) hasDuration;
- (NSTimeInterval) durationAsTimeInterval;
@ -74,6 +73,8 @@
- (id) propertyValue: (NSString *) property;
- (NSCalendarDate *) firstRecurrenceStartDate;
@end
#endif /* __NGCards_iCalEvent_H__ */

View File

@ -29,6 +29,8 @@
#import "iCalEventChanges.h"
#import "iCalDateTime.h"
#import "iCalRecurrenceRule.h"
#import "iCalRecurrenceCalculator.h"
#import "iCalEvent.h"
@ -288,4 +290,10 @@
return [self performSelector: NSSelectorFromString (method)];
}
- (NSCalendarDate *) firstRecurrenceStartDate
{
return [self firstRecurrenceStartDateWithEndDate: [self endDate]];
}
@end /* iCalEvent */

View File

@ -68,6 +68,8 @@
/* this is the outmost bound possible, not necessarily the real last date */
- (NSCalendarDate *)lastPossibleRecurrenceStartDateUsingFirstInstanceCalendarDateRange:(NGCalendarDateRange *)_r;
- (NSCalendarDate *) firstRecurrenceStartDateWithEndDate: (NSCalendarDate *) endDate;
@end
#endif /* __NGCards_iCalRepeatableEntityObject_H_ */

View File

@ -259,4 +259,74 @@ lastPossibleRecurrenceStartDateUsingFirstInstanceCalendarDateRange: (NGCalendarD
return date;
}
- (NSCalendarDate *) firstRecurrenceStartDateWithEndDate: (NSCalendarDate *) endDate
{
NSCalendarDate *startDate, *firstOccurrenceStartDate, *endOfFirstRange;
NGCalendarDateRange *range, *firstInstanceRange;
iCalRecurrenceFrequency frequency;
iCalRecurrenceRule *rule;
NSArray *rules, *recurrences;
uint32_t units;
firstOccurrenceStartDate = nil;
rules = [self recurrenceRules];
if ([rules count] > 0)
{
rule = [rules objectAtIndex: 0];
frequency = [rule frequency];
units = [rule repeatInterval];
startDate = [self startDate];
switch (frequency)
{
/* second-based units */
case iCalRecurrenceFrequenceWeekly:
units *= 7;
case iCalRecurrenceFrequenceDaily:
units *= 24;
case iCalRecurrenceFrequenceHourly:
units *= 60;
case iCalRecurrenceFrequenceMinutely:
units *= 60;
case iCalRecurrenceFrequenceSecondly:
endOfFirstRange = [startDate dateByAddingYears: 0 months: 0 days: 0
hours: 0 minutes: 0
seconds: units];
break;
/* month-based units */
case iCalRecurrenceFrequenceYearly:
units *= 12;
case iCalRecurrenceFrequenceMonthly:
endOfFirstRange = [startDate dateByAddingYears: 0 months: (units + 1)
days: 0
hours: 0 minutes: 0
seconds: 0];
break;
default:
endOfFirstRange = nil;
}
if (endOfFirstRange)
{
range = [NGCalendarDateRange calendarDateRangeWithStartDate: startDate
endDate: endOfFirstRange];
firstInstanceRange = [NGCalendarDateRange calendarDateRangeWithStartDate: startDate
endDate: endDate];
recurrences = [iCalRecurrenceCalculator recurrenceRangesWithinCalendarDateRange: range
firstInstanceCalendarDateRange: firstInstanceRange
recurrenceRules: rules
exceptionRules: nil
exceptionDates: nil];
if ([recurrences count] > 0)
firstOccurrenceStartDate = [[recurrences objectAtIndex: 0]
startDate];
}
}
return firstOccurrenceStartDate;
}
@end