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 #import <NGExtensions/NSCalendarDate+misc.h>
24 #import "iCalRecurrenceCalculator.h"
26 @interface iCalYearlyRecurrenceCalculator : iCalRecurrenceCalculator
29 #import <NGExtensions/NGCalendarDateRange.h>
30 #import "iCalRecurrenceRule.h"
31 #import "NSCalendarDate+ICal.h"
33 @interface iCalRecurrenceCalculator(PrivateAPI)
34 - (NSCalendarDate *)lastInstanceStartDate;
37 @implementation iCalYearlyRecurrenceCalculator
39 - (NSArray *)recurrenceRangesWithinCalendarDateRange:(NGCalendarDateRange *)_r{
40 NSMutableArray *ranges;
41 NSCalendarDate *firStart, *rStart, *rEnd, *until;
42 unsigned i, count, interval;
45 firStart = [self->firstRange startDate];
46 rStart = [_r startDate];
48 interval = [self->rrule repeatInterval];
49 until = [self lastInstanceStartDate];
52 if ([until compare:rStart] == NSOrderedAscending)
54 if ([until compare:rEnd] == NSOrderedDescending)
58 diff = [firStart yearsBetweenDate:rStart];
59 if ((diff != 0) && [rStart compare:firStart] == NSOrderedAscending)
62 count = [rStart yearsBetweenDate:rEnd] + 1;
63 ranges = [NSMutableArray arrayWithCapacity:count];
64 for (i = 0 ; i < count; i++) {
68 if ((test >= 0) && (test % interval) == 0) {
69 NSCalendarDate *start, *end;
70 NGCalendarDateRange *r;
72 start = [firStart dateByAddingYears:diff + i
75 [start setTimeZone:[firStart timeZone]];
76 end = [start addTimeInterval:[self->firstRange duration]];
77 r = [NGCalendarDateRange calendarDateRangeWithStartDate:start
79 if ([_r containsDateRange:r])
86 - (NSCalendarDate *)lastInstanceStartDate {
87 if ([self->rrule repeatCount] > 0) {
88 NSCalendarDate *until;
89 unsigned years, interval;
91 interval = [self->rrule repeatInterval];
92 years = [self->rrule repeatCount] * interval;
93 until = [[self->firstRange startDate] dateByAddingYears:years
98 return [super lastInstanceStartDate];
101 @end /* iCalYearlyRecurrenceCalculator */