summaryrefslogtreecommitdiff
path: root/Juick
diff options
context:
space:
mode:
Diffstat (limited to 'Juick')
-rw-r--r--Juick/Helpers/NSDate+TimeAgo.h19
-rw-r--r--Juick/Helpers/NSDate+TimeAgo.m46
-rw-r--r--Juick/Supporting Files/Juick-Prefix.pch3
-rw-r--r--Juick/Views/MessageCell.m4
4 files changed, 69 insertions, 3 deletions
diff --git a/Juick/Helpers/NSDate+TimeAgo.h b/Juick/Helpers/NSDate+TimeAgo.h
new file mode 100644
index 0000000..5ba31a7
--- /dev/null
+++ b/Juick/Helpers/NSDate+TimeAgo.h
@@ -0,0 +1,19 @@
+//
+// TimeAgo.h
+// Juick
+//
+// Created by Vitaly Takmazov on 10.12.2019.
+// Copyright © 2019 com.juick. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface NSDate(TimeAgo)
+
+- (NSString *)timeAgo;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/Juick/Helpers/NSDate+TimeAgo.m b/Juick/Helpers/NSDate+TimeAgo.m
new file mode 100644
index 0000000..860e1bc
--- /dev/null
+++ b/Juick/Helpers/NSDate+TimeAgo.m
@@ -0,0 +1,46 @@
+//
+// TimeAgo.m
+// Juick
+//
+// Created by Vitaly Takmazov on 10.12.2019.
+// Copyright © 2019 com.juick. All rights reserved.
+//
+
+#import "NSDate+TimeAgo.h"
+
+@implementation NSDate(TimeAgo)
+
+- (NSString *)timeAgo {
+ NSDateComponentsFormatter *formatter = [[NSDateComponentsFormatter alloc] init];
+ formatter.unitsStyle = NSDateComponentsFormatterUnitsStyleFull;
+
+ NSDate *now = [NSDate date];
+
+ NSCalendar *calendar = [NSCalendar currentCalendar];
+ NSDateComponents *components = [calendar components:(NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitWeekOfMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond)
+ fromDate:self
+ toDate:now
+ options:0];
+
+ if (components.year > 0) {
+ formatter.allowedUnits = NSCalendarUnitYear;
+ } else if (components.month > 0) {
+ formatter.allowedUnits = NSCalendarUnitMonth;
+ } else if (components.weekOfMonth > 0) {
+ formatter.allowedUnits = NSCalendarUnitWeekOfMonth;
+ } else if (components.day > 0) {
+ formatter.allowedUnits = NSCalendarUnitDay;
+ } else if (components.hour > 0) {
+ formatter.allowedUnits = NSCalendarUnitHour;
+ } else if (components.minute > 0) {
+ formatter.allowedUnits = NSCalendarUnitMinute;
+ } else {
+ formatter.allowedUnits = NSCalendarUnitSecond;
+ }
+
+ NSString *formatString = NSLocalizedString(@"%@ ago", @"Used to say how much time has passed. e.g. '2 hours ago'");
+
+ return [NSString stringWithFormat:formatString, [formatter stringFromDateComponents:components]];
+}
+
+@end
diff --git a/Juick/Supporting Files/Juick-Prefix.pch b/Juick/Supporting Files/Juick-Prefix.pch
index 2e32df2..7278b52 100644
--- a/Juick/Supporting Files/Juick-Prefix.pch
+++ b/Juick/Supporting Files/Juick-Prefix.pch
@@ -18,6 +18,5 @@
#import <UserNotifications/UserNotifications.h>
#import "UIImage+Utils.h"
- #import <DateTools/DateTools.h>
- #import <UIView+Shimmer.h>
+ #import "UIView+Shimmer.h"
#endif
diff --git a/Juick/Views/MessageCell.m b/Juick/Views/MessageCell.m
index c3a8afd..a64b7c3 100644
--- a/Juick/Views/MessageCell.m
+++ b/Juick/Views/MessageCell.m
@@ -10,6 +10,8 @@
#import "APIClient.h"
#import "Entity.h"
+#import "NSDate+TimeAgo.h"
+
@interface MessageCell()
@property(nonatomic, readonly) NSMutableParagraphStyle *quoteStyle;
@property(nonatomic, readonly) UIFont *boldFont;
@@ -80,7 +82,7 @@ const NSString *unreadMarker = @"●";
}
self.title.text = msg.user.uname;
- self.timestamp.text = [[[APIClient sharedClient].dateFormatter dateFromString:msg.timestamp] timeAgoSinceNow];
+ self.timestamp.text = [[[APIClient sharedClient].dateFormatter dateFromString:msg.timestamp] timeAgo];
NSUInteger count = [msg.repliesCount unsignedIntegerValue];
if (count > 0) {
if ([msg.repliesBy length] > 0) {