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 iCalDailyRecurrenceCalculator : iCalRecurrenceCalculator
27 #include <NGExtensions/NGCalendarDateRange.h>
28 #include "iCalRecurrenceRule.h"
29 #include "NSCalendarDate+ICal.h"
32 @interface iCalRecurrenceCalculator(PrivateAPI)
33 - (NSCalendarDate *)lastInstanceStartDate;
36 @implementation iCalDailyRecurrenceCalculator
38 - (NSArray *)recurrenceRangesWithinCalendarDateRange:(NGCalendarDateRange *)_r{
39 NSMutableArray *ranges;
40 NSCalendarDate *firStart;
41 long i, jnFirst, jnStart, jnEnd, startEndCount;
44 firStart = [self->firstRange startDate];
45 jnFirst = [firStart julianNumber];
46 jnEnd = [[_r endDate] julianNumber];
51 jnStart = [[_r startDate] julianNumber];
52 interval = [self->rrule repeatInterval];
54 /* if rule is bound, check the bounds */
55 if (![self->rrule isInfinite]) {
56 NSCalendarDate *until;
59 until = [self->rrule untilDate];
61 if ([until compare:[_r startDate]] == NSOrderedAscending)
63 jnRuleLast = [until julianNumber];
66 jnRuleLast = (interval * [self->rrule repeatCount])
68 if (jnRuleLast < jnStart)
71 /* jnStart < jnRuleLast < jnEnd ? */
72 if (jnEnd > jnRuleLast)
76 startEndCount = (jnEnd - jnStart) + 1;
77 ranges = [NSMutableArray arrayWithCapacity:startEndCount];
78 for (i = 0 ; i < startEndCount; i++) {
81 jnCurrent = jnStart + i;
82 if (jnCurrent >= jnFirst) {
85 jnTest = jnCurrent - jnFirst;
86 if ((jnTest % interval) == 0) {
87 NSCalendarDate *start, *end;
88 NGCalendarDateRange *r;
90 start = [NSCalendarDate dateForJulianNumber:jnCurrent];
91 [start setTimeZone:[firStart timeZone]];
92 start = [start hour: [firStart hourOfDay]
93 minute:[firStart minuteOfHour]
94 second:[firStart secondOfMinute]];
95 end = [start addTimeInterval:[self->firstRange duration]];
96 r = [NGCalendarDateRange calendarDateRangeWithStartDate:start
98 if ([_r containsDateRange:r])
106 - (NSCalendarDate *)lastInstanceStartDate {
107 if ([self->rrule repeatCount] > 0) {
108 long jnFirst, jnRuleLast;
109 NSCalendarDate *firStart, *until;
111 firStart = [self->firstRange startDate];
112 jnFirst = [firStart julianNumber];
113 jnRuleLast = ([self->rrule repeatInterval] *
114 [self->rrule repeatCount]) +
116 until = [NSCalendarDate dateForJulianNumber:jnRuleLast];
117 until = [until hour: [firStart hourOfDay]
118 minute:[firStart minuteOfHour]
119 second:[firStart secondOfMinute]];
122 return [super lastInstanceStartDate];
125 @end /* iCalDailyRecurrenceCalculator */