diff --git a/vector/src/main/java/im/vector/app/core/date/VectorDateFormatter.kt b/vector/src/main/java/im/vector/app/core/date/VectorDateFormatter.kt index 02050b0a56..b90332212a 100644 --- a/vector/src/main/java/im/vector/app/core/date/VectorDateFormatter.kt +++ b/vector/src/main/java/im/vector/app/core/date/VectorDateFormatter.kt @@ -51,6 +51,10 @@ class VectorDateFormatter @Inject constructor(private val context: Context, DateTimeFormatter.ofPattern(DateFormat.getBestDateTimePattern(localeProvider.current(), "EEE d MMM")) } + private val messageDayWithYearFormatter by lazy { + DateTimeFormatter.ofPattern(DateFormat.getBestDateTimePattern(localeProvider.current(), "d MMM YYYY")) + } + fun formatMessageHour(localDateTime: LocalDateTime): String { return messageHourFormatter.format(localDateTime) } @@ -59,6 +63,10 @@ class VectorDateFormatter @Inject constructor(private val context: Context, return messageDayFormatter.format(localDateTime) } + fun formatMessageDayWithYear(localDateTime: LocalDateTime): String { + return messageDayWithYearFormatter.format(localDateTime) + } + /** * Formats a localized relative date time for the last 2 days, e.g, "Today, HH:MM", "Yesterday, HH:MM" or * "2 days ago, HH:MM". diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt index 1fa221974c..2039c5e709 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt @@ -92,11 +92,14 @@ class RoomSummaryItemFactory @Inject constructor(private val displayableEventFor val date = latestEvent.root.localDateTime() val currentDate = DateProvider.currentLocalDateTime() val isSameDay = date.toLocalDate() == currentDate.toLocalDate() + val withinOneYear = currentDate.minusYears(1).isBefore(date) latestFormattedEvent = displayableEventFormatter.format(latestEvent, roomSummary.isDirect.not()) latestEventTime = if (isSameDay) { dateFormatter.formatMessageHour(date) - } else { + } else if (withinOneYear) { dateFormatter.formatMessageDay(date) + } else { + dateFormatter.formatMessageDayWithYear(date) } } val typingMessage = typingHelper.getTypingMessage(roomSummary.typingUsers)