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 iCalMonthlyRecurrenceCalculator : iCalRecurrenceCalculator
27 #include <NGExtensions/NGCalendarDateRange.h>
28 #include "iCalRecurrenceRule.h"
29 #include "NSCalendarDate+ICal.h"
32 @interface iCalRecurrenceCalculator(PrivateAPI)
33 - (NSCalendarDate *)lastInstanceStartDate;
36 @implementation iCalMonthlyRecurrenceCalculator
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];
50 if ([self->rrule byDayMask] != 0) {
51 [self errorWithFormat:@"cannot process byday part of rrule: %@",
57 if ([until compare:rStart] == NSOrderedAscending)
59 if ([until compare:rEnd] == NSOrderedDescending)
63 diff = [firStart monthsBetweenDate:rStart];
64 if ((diff != 0) && [rStart compare:firStart] == NSOrderedAscending)
67 count = [rStart monthsBetweenDate:rEnd] + 1;
68 ranges = [NSMutableArray arrayWithCapacity:count];
69 for (i = 0 ; i < count; i++) {
73 if ((test >= 0) && (test % interval) == 0) {
74 NSCalendarDate *start, *end;
75 NGCalendarDateRange *r;
77 start = [firStart dateByAddingYears:0
80 [start setTimeZone:[firStart timeZone]];
81 end = [start addTimeInterval:[self->firstRange duration]];
82 r = [NGCalendarDateRange calendarDateRangeWithStartDate:start
84 if ([_r containsDateRange:r])
91 - (NSCalendarDate *)lastInstanceStartDate {
92 if ([self->rrule repeatCount] > 0) {
93 NSCalendarDate *until;
94 unsigned months, interval;
96 interval = [self->rrule repeatInterval];
97 months = [self->rrule repeatCount] * interval;
98 until = [[self->firstRange startDate] dateByAddingYears:0
103 return [super lastInstanceStartDate];
106 @end /* iCalMonthlyRecurrenceCalculator */