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/NSCalendarDate+misc.h>
23 #import <NGExtensions/NGCalendarDateRange.h>
25 #import "NSCalendarDate+NGCards.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];
51 - (void) setAllDayWithStartDate: (NSCalendarDate *) newStartDate
52 duration: (unsigned int) days
54 NSCalendarDate *endDate;
56 [(iCalDateTime *) [self uniqueChildWithTag: @"dtstart"]
57 setDate: newStartDate];
58 endDate = [newStartDate dateByAddingYears: 0 months: 0 days: days];
59 [(iCalDateTime *) [self uniqueChildWithTag: @"dtend"]
63 - (void) setEndDate: (NSCalendarDate *) newEndDate
65 [(iCalDateTime *) [self uniqueChildWithTag: @"dtend"]
66 setDateTime: newEndDate];
69 - (NSCalendarDate *) endDate
71 return [(iCalDateTime *) [self uniqueChildWithTag: @"dtend"]
77 return ([[self childrenWithTag: @"dtend"] count] > 0);
80 - (void) setDuration: (NSString *) _value
82 [[self uniqueChildWithTag: @"duration"] setValue: 0
86 - (NSString *) duration
88 return [[self uniqueChildWithTag: @"duration"] value: 0];
93 return ([[self childrenWithTag: @"duration"] count] > 0);
96 - (NSTimeInterval) durationAsTimeInterval
101 P2H30M - "2 hours 30 minutes"
103 dur-value = (["+"] / "-") "P" (dur-date / dur-time / dur-week)
105 dur-date = dur-day [dur-time]
106 dur-time = "T" (dur-hour / dur-minute / dur-second)
107 dur-week = 1*DIGIT "W"
108 dur-hour = 1*DIGIT "H" [dur-minute]
109 dur-minute = 1*DIGIT "M" [dur-second]
110 dur-second = 1*DIGIT "S"
111 dur-day = 1*DIGIT "D"
113 NSTimeInterval interval;
115 if ([self hasDuration])
116 interval = [[self duration] durationAsTimeInterval];
117 else if ([self hasEndDate] && [self hasStartDate])
118 /* calculate duration using enddate */
119 interval = [[self endDate] timeIntervalSinceDate: [self startDate]];
126 - (void) setTransparency: (NSString *) _transparency
128 [[self uniqueChildWithTag: @"transp"] setValue: 0
132 - (NSString *) transparency
134 return [[self uniqueChildWithTag: @"transp"] value: 0];
143 s = [[self transparency] uppercaseString];
145 return (![s isEqualToString: @"TRANSPARENT"]);
150 return [(iCalDateTime *) [self uniqueChildWithTag: @"dtstart"] isAllDay];
153 - (BOOL) isWithinCalendarDateRange: (NGCalendarDateRange *) _range
155 NGCalendarDateRange *r;
156 NSCalendarDate *startDate, *endDate;
157 NGCalendarDateRange *fir;
159 startDate = [self startDate];
160 endDate = [self endDate];
162 if (![self isRecurrent])
164 if ([self hasStartDate] && [self hasEndDate])
166 r = [NGCalendarDateRange calendarDateRangeWithStartDate: startDate
168 return [_range containsDateRange: r];
171 return [_range containsDate: startDate];
175 fir = [NGCalendarDateRange calendarDateRangeWithStartDate:startDate
178 return [self isWithinCalendarDateRange: _range
179 firstInstanceCalendarDateRange: fir];
185 - (NSArray *) recurrenceRangesWithinCalendarDateRange: (NGCalendarDateRange *)_r
187 NGCalendarDateRange *fir;
189 if (![self isRecurrent])
192 fir = [NGCalendarDateRange calendarDateRangeWithStartDate: [self startDate]
193 endDate: [self endDate]];
194 return [self recurrenceRangesWithinCalendarDateRange:_r
195 firstInstanceCalendarDateRange:fir];
198 - (NSCalendarDate *) lastPossibleRecurrenceStartDate
200 NGCalendarDateRange *fir;
202 if (![self isRecurrent])
205 fir = [NGCalendarDateRange calendarDateRangeWithStartDate: [self startDate]
206 endDate: [self endDate]];
208 return [self lastPossibleRecurrenceStartDateUsingFirstInstanceCalendarDateRange: fir];
213 - (NSString *) entityName
220 // - (NSString *) description {
221 // NSMutableString *ms;
223 // ms = [NSMutableString stringWithCapacity:128];
224 // [ms appendFormat:@"<0x%p[%@]:", self, NSStringFromClass([self class])];
226 // if (uid) [ms appendFormat:@" uid=%@", uid];
227 // if (startDate) [ms appendFormat:@" from=%@", startDate];
228 // if (endDate) [ms appendFormat:@" to=%@", endDate];
229 // if (summary) [ms appendFormat:@" summary=%@", summary];
232 // [ms appendFormat:@" organizer=%@", organizer];
234 // [ms appendFormat:@" attendees=%@", attendees];
236 // if ([self hasAlarms])
237 // [ms appendFormat:@" alarms=%@", alarms];
239 // [ms appendString:@">"];
245 - (iCalEventChanges *) getChangesRelativeToEvent: (iCalEvent *) _event
247 return [iCalEventChanges changesFromEvent: _event