2 Copyright (C) 2004-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "iCalRecurrenceCalculator.h"
24 @interface iCalYearlyRecurrenceCalculator : iCalRecurrenceCalculator
27 #include <NGExtensions/NGCalendarDateRange.h>
28 #include "iCalRecurrenceRule.h"
29 #include "NSCalendarDate+ICal.h"
32 @interface iCalRecurrenceCalculator(PrivateAPI)
33 - (NSCalendarDate *)lastInstanceStartDate;
36 @implementation iCalYearlyRecurrenceCalculator
38 - (NSArray *)recurrenceRangesWithinCalendarDateRange:(NGCalendarDateRange *)_r{
39 NSMutableArray *ranges;
40 NSCalendarDate *firStart, *rStart, *rEnd, *until;
41 unsigned i, count, interval;
44 firStart = [self->firstRange startDate];
45 rStart = [_r startDate];
47 interval = [self->rrule repeatInterval];
48 until = [self lastInstanceStartDate];
51 if ([until compare:rStart] == NSOrderedAscending)
53 if ([until compare:rEnd] == NSOrderedDescending)
57 diff = [firStart yearsBetweenDate:rStart];
58 if ((diff != 0) && [rStart compare:firStart] == NSOrderedAscending)
61 count = [rStart yearsBetweenDate:rEnd] + 1;
62 ranges = [NSMutableArray arrayWithCapacity:count];
63 for (i = 0 ; i < count; i++) {
67 if ((test >= 0) && (test % interval) == 0) {
68 NSCalendarDate *start, *end;
69 NGCalendarDateRange *r;
71 start = [firStart dateByAddingYears:diff + i
74 [start setTimeZone:[firStart timeZone]];
75 end = [start addTimeInterval:[self->firstRange duration]];
76 r = [NGCalendarDateRange calendarDateRangeWithStartDate:start
78 if ([_r containsDateRange:r])
85 - (NSCalendarDate *)lastInstanceStartDate {
86 if ([self->rrule repeatCount] > 0) {
87 NSCalendarDate *until;
88 unsigned years, interval;
90 interval = [self->rrule repeatInterval];
91 years = [self->rrule repeatCount] * interval;
92 until = [[self->firstRange startDate] dateByAddingYears:years
97 return [super lastInstanceStartDate];
100 @end /* iCalYearlyRecurrenceCalculator */