Merge branch 'charlesmchen/tweakTimestampFormat'

pull/1/head
Matthew Chen 7 years ago
commit 170d35caaa

@ -147,7 +147,7 @@ NS_ASSUME_NONNULL_BEGIN
[self configureFonts]; [self configureFonts];
self.timestampLabel.text = [DateUtil formatTimestampShort:viewItem.interaction.timestamp]; self.timestampLabel.text = [DateUtil formatTimestampAsTimeShort:viewItem.interaction.timestamp];
} }
- (CGSize)measureWithConversationViewItem:(ConversationViewItem *)viewItem - (CGSize)measureWithConversationViewItem:(ConversationViewItem *)viewItem

@ -4823,6 +4823,9 @@ typedef enum : NSUInteger {
break; break;
} }
uint64_t viewItemTimestamp = viewItem.interaction.timestampForSorting;
OWSAssert(viewItemTimestamp > 0);
BOOL shouldShowDate = NO; BOOL shouldShowDate = NO;
if (!canShowDate) { if (!canShowDate) {
shouldShowDate = NO; shouldShowDate = NO;
@ -4830,9 +4833,12 @@ typedef enum : NSUInteger {
} else if (shouldShowDateOnNextViewItem) { } else if (shouldShowDateOnNextViewItem) {
shouldShowDate = YES; shouldShowDate = YES;
shouldShowDateOnNextViewItem = NO; shouldShowDateOnNextViewItem = NO;
} else if (previousViewItemTimestamp > 0
&& ![DateUtil isSameDayWithTimestamp:previousViewItemTimestamp timestamp:viewItemTimestamp]) {
// Ensure we always have a date break between messages on different days.
shouldShowDate = YES;
shouldShowDateOnNextViewItem = NO;
} else { } else {
uint64_t viewItemTimestamp = viewItem.interaction.timestampForSorting;
OWSAssert(viewItemTimestamp > 0);
OWSAssert(previousViewItemTimestamp > 0); OWSAssert(previousViewItemTimestamp > 0);
uint64_t timeDifferenceMs = viewItemTimestamp - previousViewItemTimestamp; uint64_t timeDifferenceMs = viewItemTimestamp - previousViewItemTimestamp;
static const uint64_t kShowTimeIntervalMs = 5 * kMinuteInMs; static const uint64_t kShowTimeIntervalMs = 5 * kMinuteInMs;
@ -4844,7 +4850,7 @@ typedef enum : NSUInteger {
viewItem.shouldShowDate = shouldShowDate; viewItem.shouldShowDate = shouldShowDate;
previousViewItemTimestamp = viewItem.interaction.timestampForSorting; previousViewItemTimestamp = viewItemTimestamp;
} }
// Update the properties of the view items. // Update the properties of the view items.

@ -23,6 +23,12 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSString *)formatTimestampShort:(uint64_t)timestamp; + (NSString *)formatTimestampShort:(uint64_t)timestamp;
+ (NSString *)formatDateShort:(NSDate *)date; + (NSString *)formatDateShort:(NSDate *)date;
+ (NSString *)formatTimestampAsTimeShort:(uint64_t)timestamp;
+ (NSString *)formatDateAsTimeShort:(NSDate *)date;
+ (BOOL)isSameDayWithTimestamp:(uint64_t)timestamp1 timestamp:(uint64_t)timestamp2;
+ (BOOL)isSameDayWithDate:(NSDate *)date1 date:(NSDate *)date2;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -187,6 +187,30 @@ static NSString *const DATE_FORMAT_WEEKDAY = @"EEEE";
return dateTimeString.uppercaseString; return dateTimeString.uppercaseString;
} }
+ (NSString *)formatTimestampAsTimeShort:(uint64_t)timestamp
{
return [self formatDateAsTimeShort:[NSDate ows_dateWithMillisecondsSince1970:timestamp]];
}
+ (NSString *)formatDateAsTimeShort:(NSDate *)date
{
OWSAssert(date);
NSString *dateTimeString = [[DateUtil timeFormatter] stringFromDate:date];
return dateTimeString.uppercaseString;
}
+ (BOOL)isSameDayWithTimestamp:(uint64_t)timestamp1 timestamp:(uint64_t)timestamp2
{
return [self isSameDayWithDate:[NSDate ows_dateWithMillisecondsSince1970:timestamp1]
date:[NSDate ows_dateWithMillisecondsSince1970:timestamp2]];
}
+ (BOOL)isSameDayWithDate:(NSDate *)date1 date:(NSDate *)date2
{
NSInteger dayDifference = [self daysFromFirstDate:date1 toSecondDate:date2];
return dayDifference == 0;
}
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

Loading…
Cancel
Save