/*
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.
*/
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];
}
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 */
@end /* NGCalendarDateRange */
+
@implementation NSArray(NGCalendarDateRanges)
- (NSArray *)arrayByCreatingDateRangesFromObjectsWithStartDateKey:(NSString *)s