261 lines
6.4 KiB
Mathematica
261 lines
6.4 KiB
Mathematica
|
/*
|
||
|
Copyright (C) 2000-2005 SKYRIX Software AG
|
||
|
|
||
|
This file is part of SOPE.
|
||
|
|
||
|
SOPE is free software; you can redistribute it and/or modify it under
|
||
|
the terms of the GNU Lesser General Public License as published by the
|
||
|
Free Software Foundation; either version 2, or (at your option) any
|
||
|
later version.
|
||
|
|
||
|
SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
|
||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||
|
License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Lesser General Public
|
||
|
License along with SOPE; see the file COPYING. If not, write to the
|
||
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
||
|
02111-1307, USA.
|
||
|
*/
|
||
|
|
||
|
#import <NGExtensions/NGCalendarDateRange.h>
|
||
|
|
||
|
#import "NSCalendarDate+NGCards.h"
|
||
|
#import "CardGroup+iCal.h"
|
||
|
#import "NSString+NGCards.h"
|
||
|
|
||
|
#import "iCalEventChanges.h"
|
||
|
#import "iCalDateTime.h"
|
||
|
|
||
|
#import "iCalEvent.h"
|
||
|
|
||
|
@implementation iCalEvent
|
||
|
|
||
|
- (Class) classForTag: (NSString *) classTag
|
||
|
{
|
||
|
Class tagClass;
|
||
|
|
||
|
if ([classTag isEqualToString: @"DURATION"]
|
||
|
|| [classTag isEqualToString: @"TRANSP"])
|
||
|
tagClass = [CardElement class];
|
||
|
else if ([classTag isEqualToString: @"DTEND"])
|
||
|
tagClass = [iCalDateTime class];
|
||
|
else
|
||
|
tagClass = [super classForTag: classTag];
|
||
|
|
||
|
return tagClass;
|
||
|
}
|
||
|
|
||
|
/* accessors */
|
||
|
|
||
|
- (void) setEndDate: (NSCalendarDate *)_date
|
||
|
{
|
||
|
[self setDate: _date forDateTimeValue: @"dtend"];
|
||
|
}
|
||
|
|
||
|
- (NSCalendarDate *) endDate
|
||
|
{
|
||
|
return [self dateForDateTimeValue: @"dtend"];
|
||
|
}
|
||
|
|
||
|
- (BOOL) hasEndDate
|
||
|
{
|
||
|
return ([[self childrenWithTag: @"dtend"] count] > 0);
|
||
|
}
|
||
|
|
||
|
- (void) setDuration: (NSString *) _value
|
||
|
{
|
||
|
[[self uniqueChildWithTag: @"duration"] setValue: 0
|
||
|
to: _value];
|
||
|
}
|
||
|
|
||
|
- (NSString *) duration
|
||
|
{
|
||
|
return [[self uniqueChildWithTag: @"duration"] value: 0];
|
||
|
}
|
||
|
|
||
|
- (BOOL) hasDuration
|
||
|
{
|
||
|
return ([[self childrenWithTag: @"duration"] count] > 0);
|
||
|
}
|
||
|
|
||
|
- (NSTimeInterval) durationAsTimeInterval
|
||
|
{
|
||
|
/*
|
||
|
eg: DURATION:PT1H
|
||
|
P - "period"
|
||
|
P2H30M - "2 hours 30 minutes"
|
||
|
|
||
|
dur-value = (["+"] / "-") "P" (dur-date / dur-time / dur-week)
|
||
|
|
||
|
dur-date = dur-day [dur-time]
|
||
|
dur-time = "T" (dur-hour / dur-minute / dur-second)
|
||
|
dur-week = 1*DIGIT "W"
|
||
|
dur-hour = 1*DIGIT "H" [dur-minute]
|
||
|
dur-minute = 1*DIGIT "M" [dur-second]
|
||
|
dur-second = 1*DIGIT "S"
|
||
|
dur-day = 1*DIGIT "D"
|
||
|
*/
|
||
|
NSTimeInterval interval;
|
||
|
|
||
|
if ([self hasDuration])
|
||
|
interval = [[self duration] durationAsTimeInterval];
|
||
|
else if ([self hasEndDate] && [self hasStartDate])
|
||
|
/* calculate duration using enddate */
|
||
|
interval = [[self endDate] timeIntervalSinceDate: [self startDate]];
|
||
|
else
|
||
|
interval = 0.0;
|
||
|
|
||
|
return interval;
|
||
|
}
|
||
|
|
||
|
- (void) setTransparency: (NSString *) _transparency
|
||
|
{
|
||
|
[[self uniqueChildWithTag: @"transp"] setValue: 0
|
||
|
to: _transparency];
|
||
|
}
|
||
|
|
||
|
- (NSString *) transparency
|
||
|
{
|
||
|
return [[self uniqueChildWithTag: @"transp"] value: 0];
|
||
|
}
|
||
|
|
||
|
/* convenience */
|
||
|
|
||
|
- (BOOL) isOpaque
|
||
|
{
|
||
|
NSString *s;
|
||
|
|
||
|
s = [[self transparency] uppercaseString];
|
||
|
|
||
|
return (![s isEqualToString: @"TRANSPARENT"]);
|
||
|
}
|
||
|
|
||
|
/* TODO: FIX THIS!
|
||
|
The problem is, that startDate/endDate are inappropriately modelled here.
|
||
|
We'd need to have a special iCalDate in order to fix all the mess.
|
||
|
For the time being, we chose allday to mean 00:00 - 23:59 in startDate's
|
||
|
timezone.
|
||
|
*/
|
||
|
- (BOOL) isAllDay
|
||
|
{
|
||
|
NSCalendarDate *ed, *startDate;
|
||
|
BOOL allDay;
|
||
|
|
||
|
if ([self hasEndDate])
|
||
|
{
|
||
|
ed = [self endDate];
|
||
|
startDate = [self startDate];
|
||
|
[ed setTimeZone: [startDate timeZone]];
|
||
|
allDay = (([startDate hourOfDay] == 0)
|
||
|
&& ([startDate minuteOfHour] == 0)
|
||
|
&& ([ed hourOfDay] == 23)
|
||
|
&& ([ed minuteOfHour] == 59));
|
||
|
}
|
||
|
else
|
||
|
allDay = NO;
|
||
|
|
||
|
return allDay;
|
||
|
}
|
||
|
|
||
|
- (BOOL) isWithinCalendarDateRange: (NGCalendarDateRange *) _range
|
||
|
{
|
||
|
NGCalendarDateRange *r;
|
||
|
NSCalendarDate *startDate, *endDate;
|
||
|
NGCalendarDateRange *fir;
|
||
|
|
||
|
startDate = [self startDate];
|
||
|
endDate = [self endDate];
|
||
|
|
||
|
if (![self isRecurrent])
|
||
|
{
|
||
|
if ([self hasStartDate] && [self hasEndDate])
|
||
|
{
|
||
|
r = [NGCalendarDateRange calendarDateRangeWithStartDate: startDate
|
||
|
endDate: endDate];
|
||
|
return [_range containsDateRange: r];
|
||
|
}
|
||
|
else
|
||
|
return [_range containsDate: startDate];
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
fir = [NGCalendarDateRange calendarDateRangeWithStartDate:startDate
|
||
|
endDate: endDate];
|
||
|
|
||
|
return [self isWithinCalendarDateRange: _range
|
||
|
firstInstanceCalendarDateRange: fir];
|
||
|
}
|
||
|
|
||
|
return NO;
|
||
|
}
|
||
|
|
||
|
- (NSArray *) recurrenceRangesWithinCalendarDateRange: (NGCalendarDateRange *)_r
|
||
|
{
|
||
|
NGCalendarDateRange *fir;
|
||
|
|
||
|
if (![self isRecurrent])
|
||
|
return nil;
|
||
|
|
||
|
fir = [NGCalendarDateRange calendarDateRangeWithStartDate: [self startDate]
|
||
|
endDate: [self endDate]];
|
||
|
return [self recurrenceRangesWithinCalendarDateRange:_r
|
||
|
firstInstanceCalendarDateRange:fir];
|
||
|
}
|
||
|
|
||
|
- (NSCalendarDate *) lastPossibleRecurrenceStartDate
|
||
|
{
|
||
|
NGCalendarDateRange *fir;
|
||
|
|
||
|
if (![self isRecurrent])
|
||
|
return nil;
|
||
|
|
||
|
fir = [NGCalendarDateRange calendarDateRangeWithStartDate: [self startDate]
|
||
|
endDate: [self endDate]];
|
||
|
|
||
|
return [self lastPossibleRecurrenceStartDateUsingFirstInstanceCalendarDateRange: fir];
|
||
|
}
|
||
|
|
||
|
/* ical typing */
|
||
|
|
||
|
- (NSString *) entityName
|
||
|
{
|
||
|
return @"vevent";
|
||
|
}
|
||
|
|
||
|
/* descriptions */
|
||
|
|
||
|
// - (NSString *) description {
|
||
|
// NSMutableString *ms;
|
||
|
|
||
|
// ms = [NSMutableString stringWithCapacity:128];
|
||
|
// [ms appendFormat:@"<0x%p[%@]:", self, NSStringFromClass([self class])];
|
||
|
|
||
|
// if (uid) [ms appendFormat:@" uid=%@", uid];
|
||
|
// if (startDate) [ms appendFormat:@" from=%@", startDate];
|
||
|
// if (endDate) [ms appendFormat:@" to=%@", endDate];
|
||
|
// if (summary) [ms appendFormat:@" summary=%@", summary];
|
||
|
|
||
|
// if (organizer)
|
||
|
// [ms appendFormat:@" organizer=%@", organizer];
|
||
|
// if (attendees)
|
||
|
// [ms appendFormat:@" attendees=%@", attendees];
|
||
|
|
||
|
// if ([self hasAlarms])
|
||
|
// [ms appendFormat:@" alarms=%@", alarms];
|
||
|
|
||
|
// [ms appendString:@">"];
|
||
|
// return ms;
|
||
|
// }
|
||
|
|
||
|
/* changes */
|
||
|
|
||
|
- (iCalEventChanges *) getChangesRelativeToEvent: (iCalEvent *) _event
|
||
|
{
|
||
|
return [iCalEventChanges changesFromEvent: _event
|
||
|
toEvent: self];
|
||
|
}
|
||
|
|
||
|
@end /* iCalEvent */
|