Shorter date for status < to 24H

This commit is contained in:
Thomas Ricouard 2023-12-27 18:05:41 +01:00
parent e53a3d0f61
commit bfa717bfa2
1 changed files with 10 additions and 2 deletions

View File

@ -6,9 +6,17 @@ private enum CodingKeys: CodingKey {
public struct ServerDate: Codable, Hashable, Equatable, Sendable {
public let asDate: Date
private let aDay: TimeInterval = 60 * 60 * 24
public var relativeFormatted: String {
DateFormatterCache.shared.createdAtRelativeFormatter.localizedString(for: asDate, relativeTo: Date())
let date = asDate
if Date().timeIntervalSince(date) >= aDay {
return DateFormatterCache.shared.createdAtRelativeFormatter.localizedString(for: date,
relativeTo: Date())
} else {
return Duration.seconds(-date.timeIntervalSinceNow).formatted(.units(width: .narrow,
maximumUnitCount: 1))
}
}
public var shortDateFormatted: String {