Skip to content

Commit 7c8a209

Browse files
author
Chris Wilson
committed
Adds a fuzzy date format based on NSDate+TimeAgo. Plan on converting to https://github.com/MatthewYork/DateTools/tree/master/DateTools once I get feedback from project. See MatthewYork/DateTools#26
1 parent 4869882 commit 7c8a209

37 files changed

Lines changed: 2664 additions & 9 deletions

CoreDataUtil.xcodeproj/project.pbxproj

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
83656E6619378FB7003D0E74 /* CoreDataUtilityStyle.m in Sources */ = {isa = PBXBuildFile; fileRef = 83656E6519378FB7003D0E74 /* CoreDataUtilityStyle.m */; };
3131
83656E6E1937A73B003D0E74 /* ObjectInfoController.m in Sources */ = {isa = PBXBuildFile; fileRef = 83656E6C1937A73B003D0E74 /* ObjectInfoController.m */; };
3232
83656E6F1937A73B003D0E74 /* ObjectInfoController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 83656E6D1937A73B003D0E74 /* ObjectInfoController.xib */; };
33+
8373BBB41A3740B3009E0297 /* NSDate+TimeAgo.m in Sources */ = {isa = PBXBuildFile; fileRef = 8373BBB21A3740B3009E0297 /* NSDate+TimeAgo.m */; };
34+
8373BBB51A3740B3009E0297 /* NSDate+TimeAgo.m in Sources */ = {isa = PBXBuildFile; fileRef = 8373BBB21A3740B3009E0297 /* NSDate+TimeAgo.m */; };
35+
8373BBB61A3740B3009E0297 /* NSDate+TimeAgo.m in Sources */ = {isa = PBXBuildFile; fileRef = 8373BBB21A3740B3009E0297 /* NSDate+TimeAgo.m */; };
36+
8373BBB71A3740B3009E0297 /* NSDateTimeAgo.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 8373BBB31A3740B3009E0297 /* NSDateTimeAgo.bundle */; };
37+
8373BBB81A3740B3009E0297 /* NSDateTimeAgo.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 8373BBB31A3740B3009E0297 /* NSDateTimeAgo.bundle */; };
38+
8373BBB91A3740B3009E0297 /* NSDateTimeAgo.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 8373BBB31A3740B3009E0297 /* NSDateTimeAgo.bundle */; };
3339
837C067B1A0E646600F4D5D4 /* MFLBuild.m in Sources */ = {isa = PBXBuildFile; fileRef = 837C067A1A0E646600F4D5D4 /* MFLBuild.m */; };
3440
838055C915A3A67200D050E7 /* ApplicationIcon-CDP.icns in Resources */ = {isa = PBXBuildFile; fileRef = 838055C715A3A67200D050E7 /* ApplicationIcon-CDP.icns */; };
3541
838055CA15A3A67200D050E7 /* ApplicationIcon-MOM.icns in Resources */ = {isa = PBXBuildFile; fileRef = 838055C815A3A67200D050E7 /* ApplicationIcon-MOM.icns */; };
@@ -131,6 +137,9 @@
131137
83656E6B1937A73B003D0E74 /* ObjectInfoController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjectInfoController.h; sourceTree = "<group>"; };
132138
83656E6C1937A73B003D0E74 /* ObjectInfoController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ObjectInfoController.m; sourceTree = "<group>"; };
133139
83656E6D1937A73B003D0E74 /* ObjectInfoController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ObjectInfoController.xib; sourceTree = "<group>"; };
140+
8373BBB11A3740B3009E0297 /* NSDate+TimeAgo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDate+TimeAgo.h"; sourceTree = "<group>"; };
141+
8373BBB21A3740B3009E0297 /* NSDate+TimeAgo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDate+TimeAgo.m"; sourceTree = "<group>"; };
142+
8373BBB31A3740B3009E0297 /* NSDateTimeAgo.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = NSDateTimeAgo.bundle; sourceTree = "<group>"; };
134143
837C06791A0E646600F4D5D4 /* MFLBuild.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MFLBuild.h; sourceTree = "<group>"; };
135144
837C067A1A0E646600F4D5D4 /* MFLBuild.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MFLBuild.m; sourceTree = "<group>"; };
136145
838055C715A3A67200D050E7 /* ApplicationIcon-CDP.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = "ApplicationIcon-CDP.icns"; sourceTree = "<group>"; };
@@ -214,6 +223,7 @@
214223
832C9698159BDB8600AC8FA8 /* Utils */ = {
215224
isa = PBXGroup;
216225
children = (
226+
8373BBAF1A37408D009E0297 /* extensions */,
217227
833FF6FB187860F1003ADCEA /* MFLConstants.h */,
218228
833FF6FC187860F1003ADCEA /* MFLConstants.m */,
219229
832C9699159BDBB000AC8FA8 /* MFLCoreDataEditorProjectLoader.h */,
@@ -259,6 +269,24 @@
259269
name = windows;
260270
sourceTree = "<group>";
261271
};
272+
8373BBAF1A37408D009E0297 /* extensions */ = {
273+
isa = PBXGroup;
274+
children = (
275+
8373BBB01A3740B3009E0297 /* timeago */,
276+
);
277+
path = extensions;
278+
sourceTree = "<group>";
279+
};
280+
8373BBB01A3740B3009E0297 /* timeago */ = {
281+
isa = PBXGroup;
282+
children = (
283+
8373BBB11A3740B3009E0297 /* NSDate+TimeAgo.h */,
284+
8373BBB21A3740B3009E0297 /* NSDate+TimeAgo.m */,
285+
8373BBB31A3740B3009E0297 /* NSDateTimeAgo.bundle */,
286+
);
287+
path = timeago;
288+
sourceTree = "<group>";
289+
};
262290
83AE7D2D19FF1A9500DD152B /* simulator */ = {
263291
isa = PBXGroup;
264292
children = (
@@ -534,6 +562,7 @@
534562
buildActionMask = 2147483647;
535563
files = (
536564
C1CEFE601463779D00466EB3 /* InfoPlist.strings in Resources */,
565+
8373BBB71A3740B3009E0297 /* NSDateTimeAgo.bundle in Resources */,
537566
C1CEFE661463779D00466EB3 /* Credits.rtf in Resources */,
538567
C1CEFE6C1463779D00466EB3 /* MainMenu.xib in Resources */,
539568
C1CEFE8B1463779D00466EB3 /* CoreDataUtilImporter.mdimporter in Resources */,
@@ -556,6 +585,7 @@
556585
buildActionMask = 2147483647;
557586
files = (
558587
C1CEFE801463779D00466EB3 /* InfoPlist.strings in Resources */,
588+
8373BBB81A3740B3009E0297 /* NSDateTimeAgo.bundle in Resources */,
559589
);
560590
runOnlyForDeploymentPostprocessing = 0;
561591
};
@@ -564,6 +594,7 @@
564594
buildActionMask = 2147483647;
565595
files = (
566596
C1CEFE991463779D00466EB3 /* InfoPlist.strings in Resources */,
597+
8373BBB91A3740B3009E0297 /* NSDateTimeAgo.bundle in Resources */,
567598
);
568599
runOnlyForDeploymentPostprocessing = 0;
569600
};
@@ -628,6 +659,7 @@
628659
5BE26B63157FE8EE00DC186E /* EntityTableView.m in Sources */,
629660
83AE7D3019FF1AB400DD152B /* SimulatorItem.m in Sources */,
630661
5BE26B67157FF22700DC186E /* EntityDataTableView.m in Sources */,
662+
8373BBB41A3740B3009E0297 /* NSDate+TimeAgo.m in Sources */,
631663
83B158FD158F6AE2002B46C2 /* MFLCoreDataIntrospection.m in Sources */,
632664
5B330A701590CB1E00D79D4D /* EntityDataTableViewCell.m in Sources */,
633665
835941221592351D0045B287 /* MFLCoreDataCommon.m in Sources */,
@@ -648,6 +680,7 @@
648680
buildActionMask = 2147483647;
649681
files = (
650682
C1CEFE831463779D00466EB3 /* CoreDataUtilTests.m in Sources */,
683+
8373BBB51A3740B3009E0297 /* NSDate+TimeAgo.m in Sources */,
651684
);
652685
runOnlyForDeploymentPostprocessing = 0;
653686
};
@@ -658,6 +691,7 @@
658691
C1CEFE9B1463779D00466EB3 /* main.c in Sources */,
659692
C1CEFE9D1463779D00466EB3 /* GetMetadataForFile.m in Sources */,
660693
C1CEFEA01463779D00466EB3 /* MySpotlightImporter.m in Sources */,
694+
8373BBB61A3740B3009E0297 /* NSDate+TimeAgo.m in Sources */,
661695
);
662696
runOnlyForDeploymentPostprocessing = 0;
663697
};

CoreDataUtil/MFLMainWindowController.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#import "FetchRequestInfoController.h"
1818
#import "ObjectInfoController.h"
1919
#import "MFLUtils.h"
20+
#import "NSDate+TimeAgo.h"
2021

2122
// max length of text to display in cell
2223
static const int MAX_TEXT_LENGTH = 255;
@@ -452,7 +453,12 @@ - (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn
452453
else if ([valueObj isKindOfClass:[NSDate class]]) {
453454
viewType = ViewTypeDate;
454455
[self setupDateFormatter];
455-
viewText = [self.dateFormatter stringFromDate:valueObj];
456+
if (self.dateStyle == NSDateFormatterShortStyle) {
457+
viewText = [valueObj timeAgo];
458+
459+
} else {
460+
viewText = [self.dateFormatter stringFromDate:valueObj];
461+
}
456462
}
457463
else if ([valueObj isKindOfClass:[NSURL class]]) {
458464
viewType = ViewTypeLink;

CoreDataUtil/MFLMainWindowController.xib

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6250" systemVersion="14B25" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6254" systemVersion="14B25" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
33
<dependencies>
44
<deployment identifier="macosx"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6250"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6254"/>
66
</dependencies>
77
<objects>
88
<customObject id="-2" userLabel="File's Owner" customClass="MFLMainWindowController">
@@ -165,7 +165,7 @@
165165
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
166166
<prototypeCellViews>
167167
<tableCellView identifier="LINK" wantsLayer="YES" id="30" userLabel="MFLButtonTableViewCell" customClass="MFLTextTableCellView">
168-
<rect key="frame" x="1" y="1" width="125.5" height="24"/>
168+
<rect key="frame" x="1" y="1" width="126" height="24"/>
169169
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
170170
<subviews>
171171
<button id="33">
@@ -197,7 +197,7 @@
197197
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
198198
<prototypeCellViews>
199199
<tableCellView identifier="TEXT" wantsLayer="YES" id="36" userLabel="MFLTextTableViewCell" customClass="MFLTextTableCellView">
200-
<rect key="frame" x="130" y="1" width="97.5" height="24"/>
200+
<rect key="frame" x="130" y="1" width="98" height="24"/>
201201
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
202202
<connections>
203203
<outlet property="cellButton" destination="33" id="aGb-lk-PwL"/>
@@ -299,14 +299,14 @@
299299
<size key="minSize" width="104" height="25"/>
300300
<size key="maxSize" width="221" height="28"/>
301301
<segmentedControl key="view" verticalHuggingPriority="750" id="142">
302-
<rect key="frame" x="0.0" y="14" width="215" height="25"/>
302+
<rect key="frame" x="1" y="14" width="214" height="25"/>
303303
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
304304
<segmentedCell key="cell" borderStyle="border" alignment="left" style="texturedSquare" trackingMode="selectOne" id="143">
305305
<font key="font" metaFont="system"/>
306306
<segments>
307-
<segment label="Short" toolTip="1/15/86 3:30pm" width="55"/>
308-
<segment label="Medium" toolTip="Medium: Jan 15, 1986" width="57" selected="YES" tag="1"/>
309-
<segment label="Long" toolTip="Long: January 15, 1986 3:30:32pm" width="55"/>
307+
<segment label="Fuzzy" toolTip="1/15/86 3:30pm" width="55"/>
308+
<segment label="Short" toolTip="Medium: Jan 15, 1986" width="57" selected="YES" tag="1"/>
309+
<segment label="Medium" toolTip="Long: January 15, 1986 3:30:32pm" width="55"/>
310310
<segment label="Full" toolTip="Full: Wednesday, January 15, 1986 AD 3:30:32pm CST"/>
311311
</segments>
312312
</segmentedCell>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#import <Foundation/Foundation.h>
2+
3+
@interface NSDate (TimeAgo)
4+
- (NSString *) timeAgoSimple;
5+
- (NSString *) timeAgo;
6+
- (NSString *) timeAgoWithLimit:(NSTimeInterval)limit;
7+
- (NSString *) timeAgoWithLimit:(NSTimeInterval)limit dateFormat:(NSDateFormatterStyle)dFormatter andTimeFormat:(NSDateFormatterStyle)tFormatter;
8+
- (NSString *) timeAgoWithLimit:(NSTimeInterval)limit dateFormatter:(NSDateFormatter *)formatter;
9+
10+
11+
// this method only returns "{value} {unit} ago" strings and no "yesterday"/"last month" strings
12+
- (NSString *)dateTimeAgo;
13+
14+
// this method gives when possible the date compared to the current calendar date: "this morning"/"yesterday"/"last week"/..
15+
// when more precision is needed (= less than 6 hours ago) it returns the same output as dateTimeAgo
16+
- (NSString *)dateTimeUntilNow;
17+
18+
@end
19+
20+
21+

0 commit comments

Comments
 (0)