-
Notifications
You must be signed in to change notification settings - Fork 0
/
JTCalendarDataCache.m
executable file
·64 lines (49 loc) · 1.23 KB
/
JTCalendarDataCache.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// JTCalendarDataCache.m
// JTCalendar
//
// Created by Jonathan Tribouharet
//
#import "JTCalendarDataCache.h"
#import "JTCalendar.h"
@interface JTCalendarDataCache(){
NSMutableDictionary *events;
NSDateFormatter *dateFormatter;
};
@end
@implementation JTCalendarDataCache
- (instancetype)init
{
self = [super init];
if(!self){
return nil;
}
dateFormatter = [NSDateFormatter new];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
events = [NSMutableDictionary new];
return self;
}
- (void)reloadData
{
[events removeAllObjects];
}
- (BOOL)haveEvent:(NSDate *)date
{
if(!self.calendarManager.dataSource){
return NO;
}
if(!self.calendarManager.calendarAppearance.useCacheSystem){
return [self.calendarManager.dataSource calendarHaveEvent:self.calendarManager date:date];
}
BOOL haveEvent;
NSString *key = [dateFormatter stringFromDate:date];
if(events[key] != nil){
haveEvent = [events[key] boolValue];
}
else{
haveEvent = [self.calendarManager.dataSource calendarHaveEvent:self.calendarManager date:date];
events[key] = [NSNumber numberWithBool:haveEvent];
}
return haveEvent;
}
@end