X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=sope-core%2FNGExtensions%2FNGCalendarDateRange.m;h=3e491fa70308539ca69bbb296716eee1d3b5722f;hb=978cb216bb2ec309a377e45b29f4adcea9407c4d;hp=74e5ce7ee245d4794c9d4dd1fe03b87048c2cec3;hpb=7eadc020be39163d31271943ebe303a97725794e;p=sope diff --git a/sope-core/NGExtensions/NGCalendarDateRange.m b/sope-core/NGExtensions/NGCalendarDateRange.m index 74e5ce7e..3e491fa7 100644 --- a/sope-core/NGExtensions/NGCalendarDateRange.m +++ b/sope-core/NGExtensions/NGCalendarDateRange.m @@ -1,20 +1,20 @@ /* Copyright (C) 2004 Marcus Mueller - This file is part of OpenGroupware.org. + This file is part of SOPE. - OGo is free software; you can redistribute it and/or modify it under + 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. - OGo is distributed in the hope that it will be useful, but WITHOUT ANY + 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 OGo; 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. */ @@ -81,11 +81,20 @@ c = self->startDate; d = self->endDate; } + // [a;b[ ?< [c;d[ if ([b compare:c] == NSOrderedAscending) return nil; // no intersection - if ([b compare:d] == NSOrderedAscending) - return [NGCalendarDateRange calendarDateRangeWithStartDate:c endDate:b]; - + // b ?< d + if ([b compare:d] == NSOrderedAscending) { + // c !< b && b !< d -> [c;b[ + if([c compare:b] == NSOrderedSame) + return nil; // no real range, thus return nil! + else + return [NGCalendarDateRange calendarDateRangeWithStartDate:c endDate:b]; + } + if([c compare:d] == NSOrderedSame) + return nil; // no real range, thus return nil! + // b !> d -> [c;d[ return [NGCalendarDateRange calendarDateRangeWithStartDate:c endDate:d]; } @@ -116,9 +125,32 @@ return [NGCalendarDateRange calendarDateRangeWithStartDate:a endDate:b]; } -- (BOOL)containsDate:(NSCalendarDate *)date { - return ([self->startDate earlierDate:date] == self->startDate && - [self->endDate laterDate:date] == self->endDate) ? YES : NO; +- (BOOL)containsDate:(NSCalendarDate *)_date { + NSComparisonResult result; + + result = [self->startDate compare:_date]; + if (!((result == NSOrderedSame) || (result == NSOrderedAscending))) + return NO; + result = [self->endDate compare:_date]; + if (result == NSOrderedAscending) + return NO; + return YES; +} + +- (BOOL)containsDateRange:(NGCalendarDateRange *)_range { + NSComparisonResult result; + + result = [self->startDate compare:[_range startDate]]; + if (!((result == NSOrderedSame) || (result == NSOrderedAscending))) + return NO; + result = [self->endDate compare:[_range endDate]]; + if (result == NSOrderedAscending) + return NO; + return YES; +} + +- (NSTimeInterval)duration { + return [self->endDate timeIntervalSinceDate:self->startDate]; } /* comparison */ @@ -164,6 +196,7 @@ @end /* NGCalendarDateRange */ + @implementation NSArray(NGCalendarDateRanges) - (NSArray *)arrayByCreatingDateRangesFromObjectsWithStartDateKey:(NSString *)s