Revision: 28337
          http://sourceforge.net/p/bibdesk/svn/28337
Author:   hofman
Date:     2023-09-13 08:57:00 +0000 (Wed, 13 Sep 2023)
Log Message:
-----------
no need for cahced date accessors and some declarations

Modified Paths:
--------------
    trunk/bibdesk/BDSKCondition.m

Modified: trunk/bibdesk/BDSKCondition.m
===================================================================
--- trunk/bibdesk/BDSKCondition.m       2023-09-12 21:52:15 UTC (rev 28336)
+++ trunk/bibdesk/BDSKCondition.m       2023-09-13 08:57:00 UTC (rev 28337)
@@ -49,16 +49,10 @@
 #import "BibDocument.h"
 
 
-@interface BDSKCondition (Private)
+@interface BDSKCondition ()
 - (BOOL)item:(BibItem *)item isContainedInGroupForField:(NSString *)field;
-- (NSDate *)cachedEndDate;
-- (void)setCachedEndDate:(NSDate *)newCachedDate;
-- (NSDate *)cachedStartDate;
-- (void)setCachedStartDate:(NSDate *)newCachedDate;
 - (void)invalidateCachedDates;
 - (void)getCachedDatesIfNeeded;
-- (void)getStartDate:(NSDate **)startDate endDate:(NSDate **)endDate;
-- (void)refreshCachedDate:(NSTimer *)timer;
 @end
 
 @implementation BDSKCondition
@@ -661,10 +655,6 @@
     }
 }
 
-@end
-
-@implementation BDSKCondition (Private)
-
 - (BOOL)item:(BibItem *)item isContainedInGroupForField:(NSString *)field {
     id value = stringValue;
     if ([field isPersonField]) {
@@ -677,86 +667,6 @@
 
 #pragma mark Cached dates
 
-- (NSDate *)cachedEndDate {
-    return cachedEndDate;
-}
-
-- (void)setCachedEndDate:(NSDate *)newCachedDate {
-    if (cachedEndDate != newCachedDate) {
-        [cachedEndDate release];
-        cachedEndDate = [newCachedDate retain];
-       }
-}
-
-- (NSDate *)cachedStartDate {
-    return cachedStartDate;
-}
-
-- (void)setCachedStartDate:(NSDate *)newCachedDate {
-    if (cachedStartDate != newCachedDate) {
-        [cachedStartDate release];
-        cachedStartDate = [newCachedDate retain];
-       }
-}
-
-- (void)invalidateCachedDates {
-    [cacheTimer invalidate];
-    cacheTimer = nil;
-    
-    [self setCachedStartDate:nil];
-    [self setCachedEndDate:nil];
-}
-
-- (void)getCachedDatesIfNeeded {
-    if ([self isDateCondition] == NO || group == nil || cachedStartDate || 
cachedEndDate)
-        return;
-    
-    NSDate *startDate = nil;
-    NSDate *endDate = nil;
-    
-    [self getStartDate:&startDate endDate:&endDate];
-    if (dateComparison < BDSKDate) {
-        // we fire every day at 1 second past midnight, because the condition 
changes at midnight
-        NSTimeInterval refreshInterval = 24 * 3600;
-        NSDate *fireDate = [[[NSDate date] startOfPeriod:BDSKPeriodDay] 
dateByAddingTimeInterval:refreshInterval + 1];
-        cacheTimer = [[NSTimer alloc] initWithFireDate:fireDate 
interval:refreshInterval target:self selector:@selector(refreshCachedDate:) 
userInfo:NULL repeats:YES];
-        [[NSRunLoop currentRunLoop] addTimer:cacheTimer 
forMode:NSDefaultRunLoopMode];
-        [cacheTimer release];
-    }
-    
-    [self setCachedStartDate:startDate];
-    [self setCachedEndDate:endDate];
-}
-
-static BOOL differentDates(NSDate *date1, NSDate *date2) {
-    if (date1 == nil)
-        return date2 != nil;
-    else if (date2 == nil)
-        return date1 != nil;
-    else
-        return [date1 compare:date2] != NSOrderedSame;
-}
-
-- (void)refreshCachedDate:(NSTimer *)timer {
-    NSDate *startDate = nil;
-    NSDate *endDate = nil;
-    BOOL changed = NO;
-    
-       [self getStartDate:&startDate endDate:&endDate];
-    if (differentDates(cachedStartDate, startDate)) {
-        [self setCachedStartDate:startDate];
-        changed = YES;
-    }
-    if (differentDates(cachedEndDate, endDate)) {
-        [self setCachedEndDate:endDate];
-        changed = YES;
-    }
-    
-    if (changed && group) {
-               [[NSNotificationCenter defaultCenter] 
postNotificationName:BDSKFilterChangedNotification object:group];
-    }
-}
-
 - (void)getStartDate:(NSDate **)startDate endDate:(NSDate **)endDate {
     NSDate *today = [NSDate date];
     
@@ -765,43 +675,43 @@
             *startDate = [today startOfPeriod:BDSKPeriodDay];
             *endDate = nil;
             break;
-        case BDSKYesterday: 
+        case BDSKYesterday:
             *startDate = [today startOfPeriod:BDSKPeriodDay byAdding:-1];
             *endDate = [today startOfPeriod:BDSKPeriodDay];
             break;
-        case BDSKThisWeek: 
+        case BDSKThisWeek:
             *startDate = [today startOfPeriod:BDSKPeriodWeek];
             *endDate = nil;
             break;
-        case BDSKLastWeek: 
+        case BDSKLastWeek:
             *startDate = [today startOfPeriod:BDSKPeriodWeek byAdding:-1];
             *endDate = [today startOfPeriod:BDSKPeriodWeek];
             break;
-        case BDSKExactly: 
+        case BDSKExactly:
             *startDate = [today startOfPeriod:periodValue 
byAdding:-numberValue];
             *endDate = [today startOfPeriod:periodValue 
byAdding:1-numberValue];
             break;
-        case BDSKInLast: 
+        case BDSKInLast:
             *startDate = [today startOfPeriod:periodValue 
byAdding:1-numberValue];
             *endDate = nil;
             break;
-        case BDSKNotInLast: 
+        case BDSKNotInLast:
             *startDate = nil;
             *endDate = [today startOfPeriod:periodValue 
byAdding:1-numberValue];
             break;
-        case BDSKBetween: 
+        case BDSKBetween:
             *startDate = [today startOfPeriod:periodValue 
byAdding:-MAX(numberValue,andNumberValue)];
             *endDate = [today startOfPeriod:periodValue 
byAdding:1-MIN(numberValue,andNumberValue)];
             break;
-        case BDSKDate: 
+        case BDSKDate:
             *startDate = [dateValue startOfPeriod:BDSKPeriodDay];
             *endDate = [dateValue startOfPeriod:BDSKPeriodDay byAdding:1];
             break;
-        case BDSKAfterDate: 
+        case BDSKAfterDate:
             *startDate = [dateValue startOfPeriod:BDSKPeriodDay byAdding:1];
             *endDate = nil;
             break;
-        case BDSKBeforeDate: 
+        case BDSKBeforeDate:
             *startDate = nil;
             *endDate = [dateValue startOfPeriod:BDSKPeriodDay];
             break;
@@ -816,6 +726,66 @@
     }
 }
 
+- (void)invalidateCachedDates {
+    [cacheTimer invalidate];
+    cacheTimer = nil;
+    
+    BDSKDESTROY(cachedStartDate);
+    BDSKDESTROY(cachedEndDate);
+}
+
+static BOOL differentDates(NSDate *date1, NSDate *date2) {
+    if (date1 == nil)
+        return date2 != nil;
+    else if (date2 == nil)
+        return date1 != nil;
+    else
+        return [date1 compare:date2] != NSOrderedSame;
+}
+
+- (void)refreshCachedDates:(NSTimer *)timer {
+    NSDate *startDate = nil;
+    NSDate *endDate = nil;
+    BOOL changed = NO;
+    
+    [self getStartDate:&startDate endDate:&endDate];
+    if (differentDates(cachedStartDate, startDate)) {
+        [cachedStartDate release];
+        cachedStartDate = [startDate retain];
+        changed = YES;
+    }
+    if (differentDates(cachedEndDate, endDate)) {
+        [cachedEndDate release];
+        cachedEndDate = [startDate retain];
+        changed = YES;
+    }
+    
+    if (changed && group) {
+        [[NSNotificationCenter defaultCenter] 
postNotificationName:BDSKFilterChangedNotification object:group];
+    }
+}
+
+- (void)getCachedDatesIfNeeded {
+    if ([self isDateCondition] == NO || group == nil || cachedStartDate || 
cachedEndDate)
+        return;
+    
+    NSDate *startDate = nil;
+    NSDate *endDate = nil;
+    
+    [self getStartDate:&startDate endDate:&endDate];
+    if (dateComparison < BDSKDate) {
+        // we fire every day at 1 second past midnight, because the condition 
changes at midnight
+        NSTimeInterval refreshInterval = 24 * 3600;
+        NSDate *fireDate = [[[NSDate date] startOfPeriod:BDSKPeriodDay] 
dateByAddingTimeInterval:refreshInterval + 1];
+        cacheTimer = [[NSTimer alloc] initWithFireDate:fireDate 
interval:refreshInterval target:self selector:@selector(refreshCachedDates:) 
userInfo:NULL repeats:YES];
+        [[NSRunLoop currentRunLoop] addTimer:cacheTimer 
forMode:NSDefaultRunLoopMode];
+        [cacheTimer release];
+    }
+    
+    cachedStartDate = [startDate retain];
+    cachedEndDate = [endDate retain];
+}
+
 @end
 
 

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to