mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-08-02 21:52:19 +00:00
Monotone-Parent: 4e8caa9222644e6820515bbf312f74dbd372c2fc
Monotone-Revision: 25c172f93ef4ab6ada0aeb6ff4267e98aef8b719 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2008-12-10T18:57:55 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
Copyright (C) 2004-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
|
||||
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
|
||||
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.
|
||||
*/
|
||||
@@ -30,71 +30,78 @@
|
||||
#import "iCalRecurrenceRule.h"
|
||||
#import "NSCalendarDate+ICal.h"
|
||||
|
||||
@interface iCalRecurrenceCalculator(PrivateAPI)
|
||||
- (NSCalendarDate *)lastInstanceStartDate;
|
||||
@interface iCalRecurrenceCalculator (PrivateAPI)
|
||||
- (NSCalendarDate *) lastInstanceStartDate;
|
||||
@end
|
||||
|
||||
@implementation iCalYearlyRecurrenceCalculator
|
||||
|
||||
- (NSArray *)recurrenceRangesWithinCalendarDateRange:(NGCalendarDateRange *)_r{
|
||||
- (NSArray *)
|
||||
recurrenceRangesWithinCalendarDateRange: (NGCalendarDateRange *) _r
|
||||
{
|
||||
NSMutableArray *ranges;
|
||||
NSCalendarDate *firStart, *rStart, *rEnd, *until;
|
||||
unsigned i, count, interval;
|
||||
int diff;
|
||||
|
||||
firStart = [self->firstRange startDate];
|
||||
rStart = [_r startDate];
|
||||
rEnd = [_r endDate];
|
||||
interval = [self->rrule repeatInterval];
|
||||
until = [self lastInstanceStartDate];
|
||||
|
||||
if (until) {
|
||||
if ([until compare:rStart] == NSOrderedAscending)
|
||||
return nil;
|
||||
if ([until compare:rEnd] == NSOrderedDescending)
|
||||
rEnd = until;
|
||||
}
|
||||
|
||||
diff = [firStart yearsBetweenDate:rStart];
|
||||
if ((diff != 0) && [rStart compare:firStart] == NSOrderedAscending)
|
||||
unsigned i, count, interval;
|
||||
int diff;
|
||||
|
||||
firStart = [firstRange startDate];
|
||||
rStart = [_r startDate];
|
||||
rEnd = [_r endDate];
|
||||
interval = [rrule repeatInterval];
|
||||
until = [self lastInstanceStartDate];
|
||||
|
||||
if (until)
|
||||
{
|
||||
if ([until compare: rStart] == NSOrderedAscending)
|
||||
return nil;
|
||||
if ([until compare: rEnd] == NSOrderedDescending)
|
||||
rEnd = until;
|
||||
}
|
||||
|
||||
diff = [firStart yearsBetweenDate: rStart];
|
||||
if ((diff != 0) && [rStart compare: firStart] == NSOrderedAscending)
|
||||
diff = -diff;
|
||||
|
||||
count = [rStart yearsBetweenDate:rEnd] + 1;
|
||||
ranges = [NSMutableArray arrayWithCapacity:count];
|
||||
for (i = 0 ; i < count; i++) {
|
||||
int test;
|
||||
count = [rStart yearsBetweenDate: rEnd] + 1;
|
||||
ranges = [NSMutableArray arrayWithCapacity: count];
|
||||
for (i = 0 ; i < count; i++)
|
||||
{
|
||||
int test;
|
||||
|
||||
test = diff + i;
|
||||
if ((test >= 0) && (test % interval) == 0) {
|
||||
NSCalendarDate *start, *end;
|
||||
NGCalendarDateRange *r;
|
||||
|
||||
start = [firStart dateByAddingYears:diff + i
|
||||
months:0
|
||||
days:0];
|
||||
[start setTimeZone:[firStart timeZone]];
|
||||
end = [start addTimeInterval:[self->firstRange duration]];
|
||||
r = [NGCalendarDateRange calendarDateRangeWithStartDate:start
|
||||
endDate:end];
|
||||
if ([_r containsDateRange:r])
|
||||
[ranges addObject:r];
|
||||
test = diff + i;
|
||||
if ((test >= 0) && (test % interval) == 0)
|
||||
{
|
||||
NSCalendarDate *start, *end;
|
||||
NGCalendarDateRange *r;
|
||||
|
||||
start = [firStart dateByAddingYears: diff + i
|
||||
months: 0
|
||||
days: 0];
|
||||
[start setTimeZone: [firStart timeZone]];
|
||||
end = [start addTimeInterval: [firstRange duration]];
|
||||
r = [NGCalendarDateRange calendarDateRangeWithStartDate: start
|
||||
endDate: end];
|
||||
if ([_r containsDateRange: r])
|
||||
[ranges addObject: r];
|
||||
}
|
||||
}
|
||||
}
|
||||
return ranges;
|
||||
}
|
||||
|
||||
- (NSCalendarDate *)lastInstanceStartDate {
|
||||
if ([self->rrule repeatCount] > 0) {
|
||||
NSCalendarDate *until;
|
||||
unsigned years, interval;
|
||||
|
||||
interval = [self->rrule repeatInterval];
|
||||
years = [self->rrule repeatCount] * interval;
|
||||
until = [[self->firstRange startDate] dateByAddingYears:years
|
||||
months:0
|
||||
days:0];
|
||||
return until;
|
||||
}
|
||||
- (NSCalendarDate *) lastInstanceStartDate
|
||||
{
|
||||
if ([rrule repeatCount] > 0)
|
||||
{
|
||||
NSCalendarDate *until;
|
||||
unsigned years, interval;
|
||||
|
||||
interval = [rrule repeatInterval];
|
||||
years = [rrule repeatCount] * interval;
|
||||
until = [[firstRange startDate] dateByAddingYears: years
|
||||
months: 0
|
||||
days: 0];
|
||||
return until;
|
||||
}
|
||||
return [super lastInstanceStartDate];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user