Skip to content

Commit

Permalink
Fixes #2679 - Timestamps in room list inconsistently use absolute and…
Browse files Browse the repository at this point in the history
… relative formatting
  • Loading branch information
stefanceriu committed Jun 19, 2024
1 parent 834260c commit 4a9de65
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion ElementX/Sources/Other/Extensions/Date.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ extension Date {
return formatted(date: .omitted, time: .shortened)
} else if calendar.isDateInYesterday(self) {
// Simply "Yesterday" if it was yesterday.
return formatted(Date.RelativeFormatStyle(presentation: .named, capitalizationContext: .beginningOfSentence))
guard let yesterday = Calendar.current.date(byAdding: .day, value: -1, to: Date()) else { fatalError() }
return yesterday.formatted(Date.RelativeFormatStyle(presentation: .named, capitalizationContext: .beginningOfSentence))
} else if let sixDaysAgo = calendar.date(byAdding: .day, value: -6, to: calendar.startOfDay(for: .now)),
sixDaysAgo <= self {
// The named day if it was in the last 6 days.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
return firstTimestamp > secondTimestamp
}
.map { key, receipt in
ReadReceipt(userID: key, formattedTimestamp: receipt.dateTimestamp?.formatted(date: .omitted, time: .shortened))
ReadReceipt(userID: key, formattedTimestamp: receipt.dateTimestamp?.formattedMinimal())
}
}

Expand Down
3 changes: 3 additions & 0 deletions UnitTests/Sources/DateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class DateTests: XCTestCase {
let yesterday = calendar.date(byAdding: .hour, value: 1, to: startOfYesterday)!
XCTAssertEqual(yesterday.formattedMinimal(), yesterday.formatted(Date.RelativeFormatStyle(presentation: .named, capitalizationContext: .beginningOfSentence)))

let nearYesterday = calendar.date(byAdding: DateComponents(hour: -10), to: today)!
XCTAssertEqual(nearYesterday.formattedMinimal(), yesterday.formatted(Date.RelativeFormatStyle(presentation: .named, capitalizationContext: .beginningOfSentence)))

let threeDaysAgo = calendar.date(byAdding: .day, value: -3, to: startOfToday)!
XCTAssertEqual(threeDaysAgo.formattedMinimal(), threeDaysAgo.formatted(.dateTime.weekday(.wide)))

Expand Down
1 change: 1 addition & 0 deletions changelog.d/2679.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Timestamps in room list inconsistently use absolute and relative formatting

0 comments on commit 4a9de65

Please sign in to comment.