Change timestamp format. Ensure we always have a date break between messages on different days.

This commit is contained in:
Matthew Chen 2018-07-02 15:11:15 -04:00
parent 484be57dcc
commit d932748cd3
4 changed files with 40 additions and 4 deletions

View file

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

View file

@ -4823,6 +4823,9 @@ typedef enum : NSUInteger {
break;
}
uint64_t viewItemTimestamp = viewItem.interaction.timestampForSorting;
OWSAssert(viewItemTimestamp > 0);
BOOL shouldShowDate = NO;
if (!canShowDate) {
shouldShowDate = NO;
@ -4830,9 +4833,12 @@ typedef enum : NSUInteger {
} else if (shouldShowDateOnNextViewItem) {
shouldShowDate = YES;
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 {
uint64_t viewItemTimestamp = viewItem.interaction.timestampForSorting;
OWSAssert(viewItemTimestamp > 0);
OWSAssert(previousViewItemTimestamp > 0);
uint64_t timeDifferenceMs = viewItemTimestamp - previousViewItemTimestamp;
static const uint64_t kShowTimeIntervalMs = 5 * kMinuteInMs;
@ -4844,7 +4850,7 @@ typedef enum : NSUInteger {
viewItem.shouldShowDate = shouldShowDate;
previousViewItemTimestamp = viewItem.interaction.timestampForSorting;
previousViewItemTimestamp = viewItemTimestamp;
}
// Update the properties of the view items.

View file

@ -23,6 +23,12 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSString *)formatTimestampShort:(uint64_t)timestamp;
+ (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
NS_ASSUME_NONNULL_END

View file

@ -187,6 +187,30 @@ static NSString *const DATE_FORMAT_WEEKDAY = @"EEEE";
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
NS_ASSUME_NONNULL_END