2 Copyright (C) 2000-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/NGCalendarDateRange.h>
24 #import "NSCalendarDate+NGCards.h"
25 #import "CardGroup+iCal.h"
26 #import "NSString+NGCards.h"
28 #import "iCalEventChanges.h"
29 #import "iCalDateTime.h"
33 @implementation iCalEvent
35 - (Class) classForTag: (NSString *) classTag
39 if ([classTag isEqualToString: @"DURATION"]
40 || [classTag isEqualToString: @"TRANSP"])
41 tagClass = [CardElement class];
42 else if ([classTag isEqualToString: @"DTEND"])
43 tagClass = [iCalDateTime class];
45 tagClass = [super classForTag: classTag];
52 - (void) setEndDate: (NSCalendarDate *)_date
54 [self setDate: _date forDateTimeValue: @"dtend"];
57 - (NSCalendarDate *) endDate
59 return [self dateForDateTimeValue: @"dtend"];
64 return ([[self childrenWithTag: @"dtend"] count] > 0);
67 - (void) setDuration: (NSString *) _value
69 [[self uniqueChildWithTag: @"duration"] setValue: 0
73 - (NSString *) duration
75 return [[self uniqueChildWithTag: @"duration"] value: 0];
80 return ([[self childrenWithTag: @"duration"] count] > 0);
83 - (NSTimeInterval) durationAsTimeInterval
88 P2H30M - "2 hours 30 minutes"
90 dur-value = (["+"] / "-") "P" (dur-date / dur-time / dur-week)
92 dur-date = dur-day [dur-time]
93 dur-time = "T" (dur-hour / dur-minute / dur-second)
94 dur-week = 1*DIGIT "W"
95 dur-hour = 1*DIGIT "H" [dur-minute]
96 dur-minute = 1*DIGIT "M" [dur-second]
97 dur-second = 1*DIGIT "S"
100 NSTimeInterval interval;
102 if ([self hasDuration])
103 interval = [[self duration] durationAsTimeInterval];
104 else if ([self hasEndDate] && [self hasStartDate])
105 /* calculate duration using enddate */
106 interval = [[self endDate] timeIntervalSinceDate: [self startDate]];
113 - (void) setTransparency: (NSString *) _transparency
115 [[self uniqueChildWithTag: @"transp"] setValue: 0
119 - (NSString *) transparency
121 return [[self uniqueChildWithTag: @"transp"] value: 0];
130 s = [[self transparency] uppercaseString];
132 return (![s isEqualToString: @"TRANSPARENT"]);
136 The problem is, that startDate/endDate are inappropriately modelled here.
137 We'd need to have a special iCalDate in order to fix all the mess.
138 For the time being, we chose allday to mean 00:00 - 23:59 in startDate's
143 NSCalendarDate *ed, *startDate;
146 if ([self hasEndDate])
149 startDate = [self startDate];
150 [ed setTimeZone: [startDate timeZone]];
151 allDay = (([startDate hourOfDay] == 0)
152 && ([startDate minuteOfHour] == 0)
153 && ([ed hourOfDay] == 23)
154 && ([ed minuteOfHour] == 59));
162 - (BOOL) isWithinCalendarDateRange: (NGCalendarDateRange *) _range
164 NGCalendarDateRange *r;
165 NSCalendarDate *startDate, *endDate;
166 NGCalendarDateRange *fir;
168 startDate = [self startDate];
169 endDate = [self endDate];
171 if (![self isRecurrent])
173 if ([self hasStartDate] && [self hasEndDate])
175 r = [NGCalendarDateRange calendarDateRangeWithStartDate: startDate
177 return [_range containsDateRange: r];
180 return [_range containsDate: startDate];
184 fir = [NGCalendarDateRange calendarDateRangeWithStartDate:startDate
187 return [self isWithinCalendarDateRange: _range
188 firstInstanceCalendarDateRange: fir];
194 - (NSArray *) recurrenceRangesWithinCalendarDateRange: (NGCalendarDateRange *)_r
196 NGCalendarDateRange *fir;
198 if (![self isRecurrent])
201 fir = [NGCalendarDateRange calendarDateRangeWithStartDate: [self startDate]
202 endDate: [self endDate]];
203 return [self recurrenceRangesWithinCalendarDateRange:_r
204 firstInstanceCalendarDateRange:fir];
207 - (NSCalendarDate *) lastPossibleRecurrenceStartDate
209 NGCalendarDateRange *fir;
211 if (![self isRecurrent])
214 fir = [NGCalendarDateRange calendarDateRangeWithStartDate: [self startDate]
215 endDate: [self endDate]];
217 return [self lastPossibleRecurrenceStartDateUsingFirstInstanceCalendarDateRange: fir];
222 - (NSString *) entityName
229 // - (NSString *) description {
230 // NSMutableString *ms;
232 // ms = [NSMutableString stringWithCapacity:128];
233 // [ms appendFormat:@"<0x%p[%@]:", self, NSStringFromClass([self class])];
235 // if (uid) [ms appendFormat:@" uid=%@", uid];
236 // if (startDate) [ms appendFormat:@" from=%@", startDate];
237 // if (endDate) [ms appendFormat:@" to=%@", endDate];
238 // if (summary) [ms appendFormat:@" summary=%@", summary];
241 // [ms appendFormat:@" organizer=%@", organizer];
243 // [ms appendFormat:@" attendees=%@", attendees];
245 // if ([self hasAlarms])
246 // [ms appendFormat:@" alarms=%@", alarms];
248 // [ms appendString:@">"];
254 - (iCalEventChanges *) getChangesRelativeToEvent: (iCalEvent *) _event
256 return [iCalEventChanges changesFromEvent: _event