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
23 #include "iCalEvent.h"
24 #include "iCalPerson.h"
25 #include "iCalEventChanges.h"
28 @interface NSString(DurationTimeInterval)
29 - (NSTimeInterval)durationAsTimeInterval;
32 @implementation iCalEvent
35 [self->duration release];
36 [self->endDate release];
42 - (void)setEndDate:(NSCalendarDate *)_date {
44 if (self->endDate == _date) return;
46 self->endDate = [_date retain];
49 - (NSCalendarDate *)endDate {
50 if ([self hasEndDate])
53 if ([self hasDuration] && (self->startDate != nil)) {
54 return [[self startDate] dateByAddingYears:0 months:0 days:0
56 seconds:[self durationAsTimeInterval]];
61 return self->endDate ? YES : NO;
64 - (void)setTransp:(NSString *)_transp {
65 /* ignore transp ... (used by Evo 'TRANSP:OPAQUE') */
68 - (void)setDuration:(NSString *)_value {
69 ASSIGNCOPY(self->duration, _value);
71 - (NSString *)duration {
72 // eg: "DURATION:PT1H"
73 if ([self hasDuration])
74 return self->duration;
80 return self->duration ? YES : NO;
82 - (NSTimeInterval)durationAsTimeInterval {
86 P2H30M - "2 hours 30 minutes"
88 dur-value = (["+"] / "-") "P" (dur-date / dur-time / dur-week)
90 dur-date = dur-day [dur-time]
91 dur-time = "T" (dur-hour / dur-minute / dur-second)
92 dur-week = 1*DIGIT "W"
93 dur-hour = 1*DIGIT "H" [dur-minute]
94 dur-minute = 1*DIGIT "M" [dur-second]
95 dur-second = 1*DIGIT "S"
100 return [self->duration durationAsTimeInterval];
102 if (self->endDate != nil && self->startDate != nil)
103 /* calculate duration using enddate */
104 return [[self endDate] timeIntervalSinceDate:[self startDate]];
111 - (NSString *)entityName {
117 - (NSString *)description {
120 ms = [NSMutableString stringWithCapacity:128];
121 [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
123 if (self->uid) [ms appendFormat:@" uid=%@", self->uid];
124 if (self->startDate) [ms appendFormat:@" from=%@", self->startDate];
125 if (self->endDate) [ms appendFormat:@" to=%@", self->endDate];
126 if (self->summary) [ms appendFormat:@" summary=%@", self->summary];
129 [ms appendFormat:@" organizer=%@", self->organizer];
131 [ms appendFormat:@" attendees=%@", self->attendees];
133 if ([self hasAlarms])
134 [ms appendFormat:@" alarms=%@", self->alarms];
136 [ms appendString:@">"];
142 - (iCalEventChanges *)getChangesRelativeToEvent:(iCalEvent *)_event {
143 return [iCalEventChanges changesFromEvent:_event
149 @implementation NSString(DurationTimeInterval)
151 - (NSTimeInterval)durationAsTimeInterval {
155 P2H30M - "2 hours 30 minutes"
157 dur-value = (["+"] / "-") "P" (dur-date / dur-time / dur-week)
159 dur-date = dur-day [dur-time]
160 dur-time = "T" (dur-hour / dur-minute / dur-second)
161 dur-week = 1*DIGIT "W"
162 dur-hour = 1*DIGIT "H" [dur-minute]
163 dur-minute = 1*DIGIT "M" [dur-second]
164 dur-second = 1*DIGIT "S"
165 dur-day = 1*DIGIT "D"
172 if (![self hasPrefix:@"P"]) {
173 NSLog(@"Cannot parse iCal duration value: '%@'", self);
179 for (i = 1, len = [self length], isTime = NO; i < len; i++) {
182 c = [self characterAtIndex:i];
183 if (c == 't' || c == 'T') {
190 val = (val * 10) + (c - 48);
196 ti += (val * 7 * 24 * 60 * 60);
199 ti += (val * 24 * 60 * 60);
202 ti += (val * 60 * 60);
211 [self logWithFormat:@"cannot process duration unit: '%c'", c];
219 @end /* NSString(DurationTimeInterval) */