File tree Expand file tree Collapse file tree 2 files changed +10
-9
lines changed Expand file tree Collapse file tree 2 files changed +10
-9
lines changed Original file line number Diff line number Diff line change 9
9
#import < Cocoa/Cocoa.h>
10
10
11
11
12
- @interface GitXRelativeDateFormatter : NSFormatter {
13
-
14
- }
15
-
12
+ @interface GitXRelativeDateFormatter : NSFormatter
16
13
@end
Original file line number Diff line number Diff line change 14
14
15
15
#define WEEK 7
16
16
17
-
18
17
@implementation GitXRelativeDateFormatter
19
18
20
19
- (NSString *)stringForObjectValue : (id )date
@@ -41,11 +40,16 @@ - (NSString *)stringForObjectValue:(id)date
41
40
if (secondsAgo < (2 * HOUR))
42
41
return @" 1 hour ago" ;
43
42
43
+ static NSDateFormatter *midnightFormatter = nil ;
44
+ static dispatch_once_t onceToken;
45
+ dispatch_once (&onceToken, ^{
46
+ midnightFormatter = [[NSDateFormatter alloc ] init ];
47
+ midnightFormatter.dateFormat = @" yyyy-MM-dd" ;
48
+ });
49
+
44
50
// figure out # of days ago based on calender days (so yesterday is the day before today not 24 hours ago)
45
- NSDateFormatter *midnightFormmatter = [[NSDateFormatter alloc ] init ];
46
- [midnightFormmatter setDateFormat: @" yyyy-MM-dd" ];
47
- NSDate *midnightOnTargetDate = [midnightFormmatter dateFromString: [midnightFormmatter stringFromDate: date]];
48
- NSDate *midnightToday = [midnightFormmatter dateFromString: [midnightFormmatter stringFromDate: now]];
51
+ NSDate *midnightOnTargetDate = [midnightFormatter dateFromString: [midnightFormatter stringFromDate: date]];
52
+ NSDate *midnightToday = [midnightFormatter dateFromString: [midnightFormatter stringFromDate: now]];
49
53
50
54
// use NSCalendar so it will handle things like leap years correctly
51
55
NSDateComponents *components = [[NSCalendar currentCalendar ] components: (NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay)
You can’t perform that action at this time.
0 commit comments