2008-07-12 00:28:12 +02:00
|
|
|
/* iCalRepeatableEntityObject+SOGo.m - this file is part of SOGo
|
|
|
|
Copyright (C) 2004-2005 SKYRIX Software AG
|
2008-09-27 03:13:41 +02:00
|
|
|
Copyright (C) 2008 Inverse inc.
|
2008-07-12 00:28:12 +02:00
|
|
|
|
|
|
|
This file is part of OpenGroupware.org.
|
|
|
|
|
|
|
|
OGo 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.
|
|
|
|
|
|
|
|
OGo 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 OGo; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Foundation/NSArray.h>
|
2008-11-03 15:17:57 +01:00
|
|
|
#import <Foundation/NSCalendarDate.h>
|
2008-07-12 00:28:12 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSString.h>
|
2008-11-03 15:17:57 +01:00
|
|
|
#import <Foundation/NSTimeZone.h>
|
2008-07-12 00:28:12 +02:00
|
|
|
|
|
|
|
#import <NGCards/iCalRecurrenceRule.h>
|
2008-07-17 23:12:43 +02:00
|
|
|
#import <NGCards/iCalRecurrenceCalculator.h>
|
|
|
|
#import <NGExtensions/NGCalendarDateRange.h>
|
2008-07-12 00:28:12 +02:00
|
|
|
|
|
|
|
#import "iCalRepeatableEntityObject+SOGo.h"
|
|
|
|
|
|
|
|
@implementation iCalRepeatableEntityObject (SOGoExtensions)
|
|
|
|
|
|
|
|
- (NSArray *) _indexedRules: (NSArray *) rules
|
|
|
|
{
|
|
|
|
NSMutableArray *ma;
|
|
|
|
unsigned int i, count;
|
|
|
|
NSString *valuesString;
|
2008-07-14 17:14:40 +02:00
|
|
|
iCalRecurrenceRule *rule;
|
2008-07-12 00:28:12 +02:00
|
|
|
|
|
|
|
ma = nil;
|
2008-07-14 17:14:40 +02:00
|
|
|
|
2008-07-12 00:28:12 +02:00
|
|
|
count = [rules count];
|
|
|
|
if (count > 0)
|
|
|
|
{
|
2008-07-14 17:14:40 +02:00
|
|
|
ma = [NSMutableArray arrayWithCapacity: count];
|
2008-07-12 00:28:12 +02:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
rule = [rules objectAtIndex:i];
|
|
|
|
#warning we could return an NSArray instead and feed it as such to the iCalRecurrenceRule in SOGoAppointmentFolder...
|
|
|
|
valuesString = [[rule values] componentsJoinedByString: @";"];
|
|
|
|
[ma addObject: valuesString];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ma;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) cycleInfo
|
|
|
|
{
|
|
|
|
NSArray *rules;
|
|
|
|
NSString *value;
|
|
|
|
NSMutableDictionary *cycleInfo;
|
|
|
|
|
|
|
|
if ([self isRecurrent])
|
|
|
|
{
|
|
|
|
cycleInfo = [NSMutableDictionary dictionaryWithCapacity: 3];
|
|
|
|
|
|
|
|
/* rules */
|
|
|
|
rules = [self _indexedRules: [self recurrenceRules]];
|
|
|
|
if (rules)
|
|
|
|
[cycleInfo setObject: rules forKey: @"rules"];
|
|
|
|
|
|
|
|
rules = [self _indexedRules: [self exceptionRules]];
|
|
|
|
if (rules)
|
|
|
|
[cycleInfo setObject: rules forKey: @"exRules"];
|
2008-07-14 17:14:40 +02:00
|
|
|
|
|
|
|
rules = [self exceptionDates];
|
|
|
|
if ([rules count])
|
2008-07-12 00:28:12 +02:00
|
|
|
[cycleInfo setObject: rules forKey: @"exDates"];
|
|
|
|
|
|
|
|
value = [cycleInfo description];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
value = nil;
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2008-07-17 23:12:43 +02:00
|
|
|
- (NGCalendarDateRange *) firstOccurenceRange
|
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned int) occurenceInterval
|
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) doesOccurOnDate: (NSCalendarDate *) occurenceDate
|
|
|
|
{
|
|
|
|
NSArray *ranges;
|
|
|
|
NGCalendarDateRange *checkRange;
|
|
|
|
NSCalendarDate *endDate;
|
2008-11-03 15:17:57 +01:00
|
|
|
NSTimeZone *tz;
|
2008-07-17 23:12:43 +02:00
|
|
|
BOOL doesOccur;
|
2008-11-03 15:17:57 +01:00
|
|
|
signed daylightOffset;
|
2008-07-17 23:12:43 +02:00
|
|
|
|
|
|
|
doesOccur = [self isRecurrent];
|
|
|
|
if (doesOccur)
|
2008-12-30 15:47:58 +01:00
|
|
|
{
|
2008-07-17 23:12:43 +02:00
|
|
|
endDate = [occurenceDate addTimeInterval: [self occurenceInterval]];
|
|
|
|
checkRange = [NGCalendarDateRange calendarDateRangeWithStartDate: occurenceDate
|
|
|
|
endDate: endDate];
|
|
|
|
ranges = [iCalRecurrenceCalculator recurrenceRangesWithinCalendarDateRange: checkRange
|
|
|
|
firstInstanceCalendarDateRange: [self firstOccurenceRange]
|
|
|
|
recurrenceRules: [self recurrenceRules]
|
|
|
|
exceptionRules: [self exceptionRules]
|
|
|
|
exceptionDates: [self exceptionDates]];
|
|
|
|
doesOccur = [ranges dateRangeArrayContainsDate: occurenceDate];
|
|
|
|
}
|
|
|
|
|
|
|
|
return doesOccur;
|
|
|
|
}
|
|
|
|
|
2008-07-12 00:28:12 +02:00
|
|
|
@end
|