2011-03-31 23:54:25 +02:00
|
|
|
/* MAPIStoreRecurrenceUtils.m - this file is part of SOGo
|
|
|
|
*
|
2012-08-17 21:04:57 +02:00
|
|
|
* Copyright (C) 2011-2012 Inverse inc
|
2011-03-31 23:54:25 +02:00
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2011-08-12 17:02:01 +02:00
|
|
|
* the Free Software Foundation; either version 3, or (at your option)
|
2011-03-31 23:54:25 +02:00
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Foundation/NSArray.h>
|
2012-07-01 22:58:46 +02:00
|
|
|
#import <Foundation/NSCalendarDate.h>
|
2012-07-20 17:44:25 +02:00
|
|
|
#import <Foundation/NSSet.h>
|
2012-04-04 16:33:59 +02:00
|
|
|
#import <Foundation/NSString.h>
|
2015-03-06 13:23:17 +01:00
|
|
|
#import <Foundation/NSTimeZone.h>
|
2011-03-31 23:54:25 +02:00
|
|
|
|
|
|
|
#import <NGExtensions/NSCalendarDate+misc.h>
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
|
|
|
|
2012-07-01 22:58:46 +02:00
|
|
|
#import <NGCards/iCalByDayMask.h>
|
|
|
|
#import <NGCards/iCalDateTime.h>
|
|
|
|
#import <NGCards/iCalEvent.h>
|
2011-03-31 23:54:25 +02:00
|
|
|
#import <NGCards/iCalRepeatableEntityObject.h>
|
|
|
|
#import <NGCards/iCalRecurrenceRule.h>
|
2012-07-01 22:58:46 +02:00
|
|
|
#import <NGCards/iCalTimeZone.h>
|
2011-03-31 23:54:25 +02:00
|
|
|
|
2011-05-30 23:12:56 +02:00
|
|
|
#import "NSDate+MAPIStore.h"
|
2011-03-31 23:54:25 +02:00
|
|
|
#import "MAPIStoreRecurrenceUtils.h"
|
2012-07-01 22:58:46 +02:00
|
|
|
#import "MAPIStoreTypes.h"
|
2011-03-31 23:54:25 +02:00
|
|
|
|
2012-04-04 16:33:59 +02:00
|
|
|
#include <stdbool.h>
|
2011-11-09 16:02:29 +01:00
|
|
|
#include <talloc.h>
|
|
|
|
#include <util/time.h>
|
|
|
|
#include <gen_ndr/property.h>
|
|
|
|
|
2011-03-31 23:54:25 +02:00
|
|
|
@implementation iCalCalendar (MAPIStoreRecurrence)
|
|
|
|
|
|
|
|
- (void) setupRecurrenceWithMasterEntity: (iCalRepeatableEntityObject *) entity
|
|
|
|
fromRecurrencePattern: (struct RecurrencePattern *) rp
|
2015-03-06 13:23:17 +01:00
|
|
|
withExceptions: (struct ExceptionInfo *) exInfos
|
|
|
|
andExceptionCount: (uint16_t) exInfoCount
|
|
|
|
inTimeZone: (NSTimeZone *) tz
|
|
|
|
|
2011-03-31 23:54:25 +02:00
|
|
|
{
|
2012-07-01 22:58:46 +02:00
|
|
|
NSCalendarDate *startDate, *olEndDate, *untilDate, *exDate;
|
2011-03-31 23:54:25 +02:00
|
|
|
NSString *monthDay, *month;
|
2012-07-20 17:44:25 +02:00
|
|
|
NSMutableSet *exceptionDates;
|
|
|
|
NSArray *realExDates;
|
2011-03-31 23:54:25 +02:00
|
|
|
iCalRecurrenceRule *rule;
|
|
|
|
iCalByDayMask *byDayMask;
|
|
|
|
iCalWeekOccurrence weekOccurrence;
|
|
|
|
iCalWeekOccurrences dayMaskDays;
|
2012-07-20 17:44:25 +02:00
|
|
|
NSUInteger count, max;
|
2011-03-31 23:54:25 +02:00
|
|
|
NSInteger bySetPos;
|
|
|
|
unsigned char maskValue;
|
|
|
|
|
|
|
|
[entity removeAllRecurrenceRules];
|
|
|
|
[entity removeAllExceptionRules];
|
|
|
|
[entity removeAllExceptionDates];
|
|
|
|
|
|
|
|
rule = [iCalRecurrenceRule elementWithTag: @"rrule"];
|
|
|
|
[entity addToRecurrenceRules: rule];
|
|
|
|
|
|
|
|
startDate = [entity startDate];
|
|
|
|
// DEBUG(5, ("From client:\n"));
|
|
|
|
// NDR_PRINT_DEBUG(AppointmentRecurrencePattern, pattern);
|
|
|
|
|
|
|
|
memset (&dayMaskDays, 0, sizeof (iCalWeekOccurrences));
|
|
|
|
if (rp->PatternType == PatternType_Day)
|
|
|
|
{
|
|
|
|
[rule setFrequency: iCalRecurrenceFrequenceDaily];
|
|
|
|
[rule setRepeatInterval: rp->Period / SOGoMinutesPerDay];
|
|
|
|
}
|
|
|
|
else if (rp->PatternType == PatternType_Week)
|
|
|
|
{
|
|
|
|
[rule setFrequency: iCalRecurrenceFrequenceWeekly];
|
|
|
|
[rule setRepeatInterval: rp->Period];
|
|
|
|
/* MAPI values for days are the same as in NGCards */
|
|
|
|
for (count = 0; count < 7; count++)
|
|
|
|
{
|
|
|
|
maskValue = 1 << count;
|
|
|
|
if ((rp->PatternTypeSpecific.WeekRecurrencePattern & maskValue))
|
|
|
|
dayMaskDays[count] = iCalWeekOccurrenceAll;
|
|
|
|
}
|
|
|
|
byDayMask = [iCalByDayMask byDayMaskWithDays: dayMaskDays];
|
|
|
|
[rule setByDayMask: byDayMask];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (rp->RecurFrequency
|
|
|
|
== RecurFrequency_Monthly)
|
|
|
|
{
|
|
|
|
[rule setFrequency: iCalRecurrenceFrequenceMonthly];
|
|
|
|
[rule setRepeatInterval: rp->Period];
|
|
|
|
}
|
|
|
|
else if (rp->RecurFrequency
|
|
|
|
== RecurFrequency_Yearly)
|
|
|
|
{
|
|
|
|
[rule setFrequency: iCalRecurrenceFrequenceYearly];
|
|
|
|
[rule setRepeatInterval: rp->Period / 12];
|
|
|
|
month = [NSString stringWithFormat: @"%d", [startDate monthOfYear]];
|
2011-11-14 04:26:50 +01:00
|
|
|
[rule setSingleValue: month forKey: @"bymonth"];
|
2011-03-31 23:54:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
[self errorWithFormat:
|
|
|
|
@"unhandled frequency case for Month pattern type: %d",
|
|
|
|
rp->RecurFrequency];
|
|
|
|
|
|
|
|
if ((rp->PatternType & 3) == 3)
|
|
|
|
{
|
|
|
|
/* HjMonthNth and MonthNth */
|
|
|
|
if (rp->PatternTypeSpecific.MonthRecurrencePattern.WeekRecurrencePattern
|
|
|
|
== 0x7f)
|
|
|
|
{
|
|
|
|
/* firsts or last day of month */
|
|
|
|
if (rp->PatternTypeSpecific.MonthRecurrencePattern.N
|
|
|
|
== RecurrenceN_Last)
|
|
|
|
monthDay = @"-1";
|
|
|
|
else
|
|
|
|
monthDay = [NSString stringWithFormat: @"%d",
|
|
|
|
rp->PatternTypeSpecific.MonthRecurrencePattern.N];
|
2011-11-14 04:26:50 +01:00
|
|
|
[rule setSingleValue: monthDay forKey: @"bymonthday"];
|
2011-03-31 23:54:25 +02:00
|
|
|
}
|
|
|
|
else if ((rp->PatternTypeSpecific.MonthRecurrencePattern.WeekRecurrencePattern
|
|
|
|
== 0x3e) /* Nth week day */
|
|
|
|
|| (rp->PatternTypeSpecific.MonthRecurrencePattern.WeekRecurrencePattern
|
|
|
|
== 0x41)) /* Nth week-end day */
|
|
|
|
{
|
|
|
|
for (count = 0; count < 7; count++)
|
|
|
|
{
|
|
|
|
maskValue = 1 << count;
|
|
|
|
if ((rp->PatternTypeSpecific.MonthRecurrencePattern.WeekRecurrencePattern
|
|
|
|
& maskValue))
|
|
|
|
dayMaskDays[count] = iCalWeekOccurrenceAll;
|
|
|
|
}
|
|
|
|
byDayMask = [iCalByDayMask byDayMaskWithDays: dayMaskDays];
|
|
|
|
[rule setByDayMask: byDayMask];
|
|
|
|
|
|
|
|
if (rp->PatternTypeSpecific.MonthRecurrencePattern.N
|
|
|
|
== RecurrenceN_Last)
|
|
|
|
bySetPos = -1;
|
|
|
|
else
|
|
|
|
bySetPos = rp->PatternTypeSpecific.MonthRecurrencePattern.N;
|
|
|
|
|
2011-11-14 04:26:50 +01:00
|
|
|
[rule
|
|
|
|
setSingleValue: [NSString stringWithFormat: @"%d", bySetPos]
|
|
|
|
forKey: @"bysetpos"];
|
2011-03-31 23:54:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (rp->PatternTypeSpecific.MonthRecurrencePattern.N
|
|
|
|
< RecurrenceN_Last)
|
|
|
|
weekOccurrence = (1
|
|
|
|
<< (rp->PatternTypeSpecific.MonthRecurrencePattern.N
|
|
|
|
- 1));
|
|
|
|
else
|
|
|
|
weekOccurrence = iCalWeekOccurrenceLast;
|
|
|
|
|
|
|
|
for (count = 0; count < 7; count++)
|
|
|
|
{
|
|
|
|
maskValue = 1 << count;
|
|
|
|
if ((rp->PatternTypeSpecific.MonthRecurrencePattern.WeekRecurrencePattern
|
|
|
|
& maskValue))
|
|
|
|
dayMaskDays[count] = weekOccurrence;
|
|
|
|
}
|
|
|
|
byDayMask = [iCalByDayMask byDayMaskWithDays: dayMaskDays];
|
|
|
|
[rule setByDayMask: byDayMask];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((rp->PatternType & 2) == 2
|
|
|
|
|| (rp->PatternType & 4) == 4)
|
|
|
|
{
|
|
|
|
/* MonthEnd, HjMonth and HjMonthEnd */
|
2011-11-14 04:26:50 +01:00
|
|
|
[rule
|
|
|
|
setSingleValue: [NSString stringWithFormat: @"%d",
|
|
|
|
rp->PatternTypeSpecific.Day]
|
|
|
|
forKey: @"bymonthday"];
|
2011-03-31 23:54:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
[self errorWithFormat: @"invalid value for PatternType: %.4x",
|
|
|
|
rp->PatternType];
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (rp->EndType)
|
|
|
|
{
|
|
|
|
case END_NEVER_END:
|
|
|
|
case NEVER_END:
|
|
|
|
break;
|
|
|
|
case END_AFTER_N_OCCURRENCES:
|
|
|
|
[rule setRepeatCount: rp->OccurrenceCount];
|
|
|
|
break;
|
|
|
|
case END_AFTER_DATE:
|
|
|
|
olEndDate = [NSCalendarDate dateFromMinutesSince1601: rp->EndDate];
|
|
|
|
untilDate = [NSCalendarDate dateWithYear: [olEndDate yearOfCommonEra]
|
|
|
|
month: [olEndDate monthOfYear]
|
|
|
|
day: [olEndDate dayOfMonth]
|
|
|
|
hour: [startDate hourOfDay]
|
|
|
|
minute: [startDate minuteOfHour]
|
|
|
|
second: [startDate secondOfMinute]
|
|
|
|
timeZone: [startDate timeZone]];
|
|
|
|
[rule setUntilDate: untilDate];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
[self errorWithFormat: @"invalid value for EndType: %.4x",
|
|
|
|
rp->EndType];
|
|
|
|
}
|
2012-07-01 22:58:46 +02:00
|
|
|
|
2012-07-20 17:44:25 +02:00
|
|
|
/* exception dates:
|
|
|
|
- take all deleted instances
|
2015-03-06 13:23:17 +01:00
|
|
|
- remove all modified instances available in ExceptionInfo from the above set
|
2012-07-20 17:44:25 +02:00
|
|
|
- add remaining instances, in chronological order
|
|
|
|
*/
|
|
|
|
|
2015-03-06 13:23:17 +01:00
|
|
|
/* Heuristic to avoid these loops */
|
|
|
|
if (rp->DeletedInstanceCount != rp->ModifiedInstanceCount) {
|
|
|
|
exceptionDates = [NSMutableSet set];
|
|
|
|
for (count = 0; count < rp->DeletedInstanceCount; count++)
|
|
|
|
{
|
|
|
|
exDate
|
|
|
|
= [NSDate dateFromMinutesSince1601: rp->DeletedInstanceDates[count]];
|
|
|
|
exDate = [exDate hour: [startDate hourOfDay]
|
|
|
|
minute: [startDate minuteOfHour]
|
|
|
|
second: [startDate secondOfMinute]];
|
|
|
|
[exceptionDates addObject: exDate];
|
|
|
|
}
|
|
|
|
/* Read the exceptions to remove the instances that are modified and not deleted */
|
|
|
|
if (exInfos && exInfoCount > 0)
|
|
|
|
{
|
|
|
|
for (count = 0; count < exInfoCount; count++)
|
|
|
|
{
|
|
|
|
/* The OriginalStartDate is in local time */
|
|
|
|
exDate = [NSDate dateFromMinutesSince1601: exInfos[count].OriginalStartDate];
|
|
|
|
exDate = [exDate dateByAddingYears: 0 months: 0 days: 0
|
|
|
|
hours: 0 minutes: 0
|
|
|
|
seconds: - [tz secondsFromGMT]];
|
|
|
|
[exceptionDates removeObject: exDate];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
realExDates = [[exceptionDates allObjects]
|
|
|
|
sortedArrayUsingSelector: @selector (compare:)];
|
|
|
|
max = [realExDates count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
[entity addToExceptionDates: [realExDates objectAtIndex: count]];
|
|
|
|
}
|
2011-03-31 23:54:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation iCalRecurrenceRule (MAPIStoreRecurrence)
|
|
|
|
|
|
|
|
- (void) fillRecurrencePattern: (struct RecurrencePattern *) rp
|
2012-07-01 22:58:46 +02:00
|
|
|
withEvent: (iCalEvent *) event
|
|
|
|
inTimeZone: (NSTimeZone *) timeZone
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-03-31 23:54:25 +02:00
|
|
|
{
|
|
|
|
iCalRecurrenceFrequency freq;
|
|
|
|
iCalByDayMask *byDayMask;
|
|
|
|
NSString *byMonthDay, *bySetPos;
|
2012-07-20 17:44:25 +02:00
|
|
|
NSCalendarDate *startDate, *endDate, *untilDate, *beginOfWeek, *minimumDate,
|
|
|
|
*moduloDate, *midnight;
|
2011-03-31 23:54:25 +02:00
|
|
|
iCalWeekOccurrences *days;
|
2012-07-20 17:44:25 +02:00
|
|
|
NSInteger dayOfWeek, repeatInterval, repeatCount, count, firstOccurrence,
|
|
|
|
max;
|
2011-03-31 23:54:25 +02:00
|
|
|
uint32_t nbrMonths, mask;
|
2012-07-20 17:44:25 +02:00
|
|
|
NSArray *events;
|
|
|
|
NSMutableArray *deletedDates, *modifiedDates;
|
2011-03-31 23:54:25 +02:00
|
|
|
|
2012-07-01 22:58:46 +02:00
|
|
|
startDate = [event firstRecurrenceStartDate];
|
|
|
|
[startDate setTimeZone: timeZone];
|
|
|
|
endDate = [event lastPossibleRecurrenceStartDate];
|
|
|
|
[endDate setTimeZone: timeZone];
|
|
|
|
|
2011-03-31 23:54:25 +02:00
|
|
|
rp->ReaderVersion = 0x3004;
|
|
|
|
rp->WriterVersion = 0x3004;
|
|
|
|
|
|
|
|
rp->StartDate = [[startDate beginOfDay] asMinutesSince1601];
|
|
|
|
|
|
|
|
untilDate = [self untilDate];
|
|
|
|
if (untilDate)
|
|
|
|
{
|
|
|
|
rp->EndDate = [untilDate asMinutesSince1601];
|
|
|
|
rp->EndType = END_AFTER_DATE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
repeatCount = [self repeatCount];
|
|
|
|
if (repeatCount > 0)
|
|
|
|
{
|
|
|
|
rp->EndDate = [endDate asMinutesSince1601];
|
|
|
|
rp->OccurrenceCount = repeatCount;
|
|
|
|
rp->EndType = END_AFTER_N_OCCURRENCES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rp->EndDate = 0x5ae980df;
|
2012-08-06 21:19:15 +02:00
|
|
|
rp->OccurrenceCount = 0xa;
|
2011-03-31 23:54:25 +02:00
|
|
|
rp->EndType = END_NEVER_END;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
freq = [self frequency];
|
|
|
|
repeatInterval = [self repeatInterval];
|
|
|
|
if (freq == iCalRecurrenceFrequenceDaily)
|
|
|
|
{
|
|
|
|
rp->RecurFrequency = RecurFrequency_Daily;
|
|
|
|
rp->PatternType = PatternType_Day;
|
|
|
|
rp->Period = repeatInterval * SOGoMinutesPerDay;
|
|
|
|
rp->FirstDateTime = rp->StartDate % rp->Period;
|
|
|
|
}
|
|
|
|
else if (freq == iCalRecurrenceFrequenceWeekly)
|
|
|
|
{
|
|
|
|
rp->RecurFrequency = RecurFrequency_Weekly;
|
|
|
|
rp->PatternType = PatternType_Week;
|
|
|
|
rp->Period = repeatInterval;
|
2015-03-10 00:36:36 +01:00
|
|
|
|
|
|
|
dayOfWeek = [startDate dayOfWeek];
|
|
|
|
|
2011-03-31 23:54:25 +02:00
|
|
|
mask = 0;
|
|
|
|
byDayMask = [self byDayMask];
|
2015-03-10 00:36:36 +01:00
|
|
|
if (byDayMask)
|
|
|
|
{
|
|
|
|
for (count = 0; count < 7; count++)
|
|
|
|
if ([byDayMask occursOnDay: count])
|
|
|
|
mask |= 1 << count;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Set the recurrence pattern using start date */
|
|
|
|
mask |= 1 << dayOfWeek;
|
|
|
|
}
|
2011-03-31 23:54:25 +02:00
|
|
|
rp->PatternTypeSpecific.WeekRecurrencePattern = mask;
|
|
|
|
|
|
|
|
/* FirstDateTime */
|
|
|
|
if (dayOfWeek)
|
|
|
|
beginOfWeek = [startDate dateByAddingYears: 0 months: 0
|
|
|
|
days: -dayOfWeek
|
|
|
|
hours: 0 minutes: 0
|
|
|
|
seconds: 0];
|
|
|
|
else
|
|
|
|
beginOfWeek = startDate;
|
|
|
|
rp->FirstDateTime = ([[beginOfWeek beginOfDay] asMinutesSince1601]
|
|
|
|
% (repeatInterval * 10080));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (freq == iCalRecurrenceFrequenceMonthly)
|
|
|
|
{
|
|
|
|
rp->RecurFrequency = RecurFrequency_Monthly;
|
|
|
|
rp->Period = repeatInterval;
|
|
|
|
}
|
|
|
|
else if (freq == iCalRecurrenceFrequenceYearly)
|
|
|
|
{
|
|
|
|
rp->RecurFrequency = RecurFrequency_Yearly;
|
|
|
|
rp->Period = 12;
|
|
|
|
if (repeatInterval != 1)
|
|
|
|
[self errorWithFormat:
|
|
|
|
@"yearly interval '%d' cannot be converted",
|
|
|
|
repeatInterval];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[self errorWithFormat: @"frequency '%d' cannot be converted", freq];
|
|
|
|
|
|
|
|
/* FirstDateTime */
|
|
|
|
midnight = [[startDate firstDayOfMonth] beginOfDay];
|
|
|
|
minimumDate = [NSCalendarDate dateFromMinutesSince1601: 0];
|
|
|
|
nbrMonths = (([midnight yearOfCommonEra]
|
|
|
|
- [minimumDate yearOfCommonEra]) * 12
|
|
|
|
+ [midnight monthOfYear] - 1);
|
|
|
|
moduloDate = [minimumDate dateByAddingYears: 0
|
|
|
|
months: (nbrMonths % rp->Period)
|
|
|
|
days: 0 hours: 0 minutes: 0
|
|
|
|
seconds: 0];
|
|
|
|
rp->FirstDateTime = [moduloDate asMinutesSince1601];
|
|
|
|
|
|
|
|
byMonthDay = [[self byMonthDay] objectAtIndex: 0];
|
2011-11-08 19:36:52 +01:00
|
|
|
if (!byMonthDay && (freq == iCalRecurrenceFrequenceYearly))
|
|
|
|
{
|
|
|
|
byMonthDay = [NSString stringWithFormat: @"%d", [startDate dayOfMonth]];
|
|
|
|
[self warnWithFormat: @"no month day specified in yearly"
|
|
|
|
@" recurrence: we deduce it from the start date: %@",
|
|
|
|
byMonthDay];
|
|
|
|
}
|
|
|
|
|
2011-03-31 23:54:25 +02:00
|
|
|
if (byMonthDay)
|
|
|
|
{
|
|
|
|
if ([byMonthDay intValue] < 0)
|
|
|
|
{
|
|
|
|
/* This means we cannot handle values of BYMONTHDAY that are <
|
|
|
|
-7. */
|
|
|
|
rp->PatternType = PatternType_MonthNth;
|
|
|
|
rp->PatternTypeSpecific.MonthRecurrencePattern.WeekRecurrencePattern = 0x7f;
|
|
|
|
rp->PatternTypeSpecific.MonthRecurrencePattern.N = RecurrenceN_Last;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rp->PatternType = PatternType_Month;
|
|
|
|
rp->PatternTypeSpecific.Day = [byMonthDay intValue];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rp->PatternType = PatternType_MonthNth;
|
|
|
|
byDayMask = [self byDayMask];
|
|
|
|
mask = 0;
|
2011-11-08 19:36:52 +01:00
|
|
|
days = [byDayMask weekDayOccurrences];
|
|
|
|
if (days)
|
|
|
|
{
|
|
|
|
for (count = 0; count < 7; count++)
|
|
|
|
if (days[0][count])
|
|
|
|
mask |= 1 << count;
|
|
|
|
}
|
2011-03-31 23:54:25 +02:00
|
|
|
if (mask)
|
|
|
|
{
|
|
|
|
rp->PatternTypeSpecific.MonthRecurrencePattern.WeekRecurrencePattern = mask;
|
2011-11-14 04:26:50 +01:00
|
|
|
bySetPos = [self flattenedValuesForKey: @"bysetpos"];
|
2011-03-31 23:54:25 +02:00
|
|
|
if ([bySetPos length])
|
|
|
|
rp->PatternTypeSpecific.MonthRecurrencePattern.N
|
|
|
|
= ([bySetPos hasPrefix: @"-"]
|
|
|
|
? RecurrenceN_Last : [bySetPos intValue]);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
firstOccurrence = [byDayMask firstOccurrence];
|
|
|
|
if (firstOccurrence)
|
|
|
|
rp->PatternTypeSpecific.MonthRecurrencePattern.N
|
|
|
|
= ((firstOccurrence > -1)
|
|
|
|
? firstOccurrence : RecurrenceN_Last);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[self errorWithFormat: @"rule for an event that never occurs"];
|
|
|
|
}
|
|
|
|
}
|
2012-07-01 22:58:46 +02:00
|
|
|
|
2012-07-20 17:44:25 +02:00
|
|
|
events = [[event parent] events];
|
|
|
|
max = [events count];
|
|
|
|
modifiedDates = [NSMutableArray arrayWithCapacity: max];
|
|
|
|
for (count = 1; count < max; count++)
|
|
|
|
{
|
|
|
|
startDate = [[events objectAtIndex: count] recurrenceId];
|
2012-08-06 21:19:15 +02:00
|
|
|
if (startDate)
|
|
|
|
[modifiedDates addObject: startDate];
|
|
|
|
else
|
|
|
|
[self errorWithFormat: @"missing recurrence-id for event %d", count];
|
2012-07-20 17:44:25 +02:00
|
|
|
}
|
|
|
|
max = [modifiedDates count];
|
|
|
|
rp->ModifiedInstanceCount = max;
|
|
|
|
rp->ModifiedInstanceDates = talloc_array (memCtx, uint32_t, max);
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
startDate = [[modifiedDates objectAtIndex: count]
|
|
|
|
hour: 0 minute: 0 second: 0];
|
|
|
|
*(rp->ModifiedInstanceDates + count) = [startDate asMinutesSince1601];
|
|
|
|
}
|
|
|
|
|
|
|
|
deletedDates = [modifiedDates mutableCopy];
|
|
|
|
[deletedDates autorelease];
|
|
|
|
[deletedDates
|
|
|
|
addObjectsFromArray: [event exceptionDatesWithTimeZone: utcTZ]];
|
|
|
|
[deletedDates sortUsingFunction: NSDateCompare context: NULL];
|
|
|
|
|
|
|
|
max = [deletedDates count];
|
2012-07-01 22:58:46 +02:00
|
|
|
rp->DeletedInstanceCount = max;
|
|
|
|
rp->DeletedInstanceDates = talloc_array (memCtx, uint32_t, max);
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
2012-07-20 17:44:25 +02:00
|
|
|
startDate = [[deletedDates objectAtIndex: count]
|
|
|
|
hour: 0 minute: 0 second: 0];
|
2012-07-01 22:58:46 +02:00
|
|
|
*(rp->DeletedInstanceDates + count) = [startDate asMinutesSince1601];
|
|
|
|
}
|
2011-03-31 23:54:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|