]> err.no Git - sope/blobdiff - sope-core/NGExtensions/NGCalendarDateRange.m
Drop apache 1 build-dependency
[sope] / sope-core / NGExtensions / NGCalendarDateRange.m
index 1c3e9dcfa535067f2045675f605f23ecbbb71a24..da08457811f07a7f334d8903e84eda0cc2e8ebee 100644 (file)
@@ -1,20 +1,21 @@
 /*
-  Copyright (C) 2004 Marcus Mueller
+  Copyright (C) 2004-2007 Marcus Mueller
+  Copyright (C) 2007      Helge Hess
 
-  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.
 */
   return [NGCalendarDateRange calendarDateRangeWithStartDate:a endDate:b];
 }
 
-- (BOOL)containsDate:(NSCalendarDate *)date {
-  return ([self->startDate earlierDate:date] == self->startDate && 
-         [self->endDate compare:date] == NSOrderedDescending) ? 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 */
   return [self->startDate compare:[other startDate]];
 }
 
+/* KVC */
+
+- (id)valueForUndefinedKey:(NSString *)_key {
+  /* eg this is used in OGo on 'dateId' to probe for event objects */
+  return nil;
+}
+
 /* description */
 
 - (NSString *)description {
 
 @end /* NGCalendarDateRange */
 
+
 @implementation NSArray(NGCalendarDateRanges)
 
 - (NSArray *)arrayByCreatingDateRangesFromObjectsWithStartDateKey:(NSString *)s