2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo 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 OGo 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 OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "iCalEvent.h"
23 #include "iCalPerson.h"
24 #include "iCalEventChanges.h"
25 #include "iCalRenderer.h"
28 @interface NSString(DurationTimeInterval)
29 - (NSTimeInterval)durationAsTimeInterval;
32 @implementation iCalEvent
35 [self->duration release];
36 [self->endDate release];
37 [self->recurrenceRule release];
43 - (void)setEndDate:(NSCalendarDate *)_date {
45 if (self->endDate == _date) return;
47 self->endDate = [_date retain];
50 - (NSCalendarDate *)endDate {
51 if ([self hasEndDate])
54 if ([self hasDuration] && (self->startDate != nil)) {
55 return [[self startDate] dateByAddingYears:0 months:0 days:0
57 seconds:[self durationAsTimeInterval]];
62 return self->endDate ? YES : NO;
65 - (void)setTransp:(NSString *)_transp {
66 /* ignore transp ... (used by Evo 'TRANSP:OPAQUE') */
69 - (void)setDuration:(NSString *)_value {
70 ASSIGNCOPY(self->duration, _value);
72 - (NSString *)duration {
73 // eg: "DURATION:PT1H"
74 if ([self hasDuration])
75 return self->duration;
81 return self->duration ? YES : NO;
83 - (NSTimeInterval)durationAsTimeInterval {
87 P2H30M - "2 hours 30 minutes"
89 dur-value = (["+"] / "-") "P" (dur-date / dur-time / dur-week)
91 dur-date = dur-day [dur-time]
92 dur-time = "T" (dur-hour / dur-minute / dur-second)
93 dur-week = 1*DIGIT "W"
94 dur-hour = 1*DIGIT "H" [dur-minute]
95 dur-minute = 1*DIGIT "M" [dur-second]
96 dur-second = 1*DIGIT "S"
101 return [self->duration durationAsTimeInterval];
103 if (self->endDate != nil && self->startDate != nil)
104 /* calculate duration using enddate */
105 return [[self endDate] timeIntervalSinceDate:[self startDate]];
110 - (void)setRecurrenceRule:(NSString *)_recurrenceRule {
111 ASSIGN(self->recurrenceRule, _recurrenceRule);
113 - (NSString *)recurrenceRule {
114 return self->recurrenceRule;
119 - (NSString *)entityName {
125 - (NSString *)description {
128 ms = [NSMutableString stringWithCapacity:128];
129 [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
131 if (self->uid) [ms appendFormat:@" uid=%@", self->uid];
132 if (self->startDate) [ms appendFormat:@" from=%@", self->startDate];
133 if (self->endDate) [ms appendFormat:@" to=%@", self->endDate];
134 if (self->summary) [ms appendFormat:@" summary=%@", self->summary];
137 [ms appendFormat:@" organizer=%@", self->organizer];
139 [ms appendFormat:@" attendees=%@", self->attendees];
141 if ([self hasAlarms])
142 [ms appendFormat:@" alarms=%@", self->alarms];
144 if (self->recurrenceRule)
145 [ms appendFormat:@" recurrenceRule=%@", self->recurrenceRule];
147 [ms appendString:@">"];
153 - (iCalEventChanges *)getChangesRelativeToEvent:(iCalEvent *)_event {
154 return [iCalEventChanges changesFromEvent:_event
158 /* generating iCal content */
160 - (NSString *)vEventString {
161 return [[iCalRenderer sharedICalendarRenderer] vEventStringForEvent:self];
166 @implementation NSString(DurationTimeInterval)
168 - (NSTimeInterval)durationAsTimeInterval {
172 P2H30M - "2 hours 30 minutes"
174 dur-value = (["+"] / "-") "P" (dur-date / dur-time / dur-week)
176 dur-date = dur-day [dur-time]
177 dur-time = "T" (dur-hour / dur-minute / dur-second)
178 dur-week = 1*DIGIT "W"
179 dur-hour = 1*DIGIT "H" [dur-minute]
180 dur-minute = 1*DIGIT "M" [dur-second]
181 dur-second = 1*DIGIT "S"
182 dur-day = 1*DIGIT "D"
189 if (![self hasPrefix:@"P"]) {
190 NSLog(@"Cannot parse iCal duration value: '%@'", self);
196 for (i = 1, len = [self length], isTime = NO; i < len; i++) {
199 c = [self characterAtIndex:i];
200 if (c == 't' || c == 'T') {
207 val = (val * 10) + (c - 48);
213 ti += (val * 7 * 24 * 60 * 60);
216 ti += (val * 24 * 60 * 60);
219 ti += (val * 60 * 60);
228 [self logWithFormat:@"cannot process duration unit: '%c'", c];
236 @end /* NSString(DurationTimeInterval) */