mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-12-23 05:19:42 +01:00
Better date pre compute
This commit is contained in:
parent
8f0548f45d
commit
f3043b608c
@ -6,11 +6,11 @@ private enum CodingKeys: CodingKey {
|
||||
|
||||
public struct ServerDate: Codable, Hashable, Equatable, Sendable {
|
||||
public let asDate: Date
|
||||
private let aDay: TimeInterval = 60 * 60 * 24
|
||||
private let isOlderThanADay: Bool
|
||||
|
||||
public var relativeFormatted: String {
|
||||
let date = asDate
|
||||
if Date().timeIntervalSince(date) >= aDay {
|
||||
if isOlderThanADay {
|
||||
return DateFormatterCache.shared.createdAtRelativeFormatter.localizedString(for: date,
|
||||
relativeTo: Date())
|
||||
} else {
|
||||
@ -27,6 +27,7 @@ public struct ServerDate: Codable, Hashable, Equatable, Sendable {
|
||||
|
||||
public init() {
|
||||
asDate = Date() - 100
|
||||
isOlderThanADay = false
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
@ -40,6 +41,9 @@ public struct ServerDate: Codable, Hashable, Equatable, Sendable {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
asDate = try container.decode(Date.self, forKey: .asDate)
|
||||
}
|
||||
|
||||
let aDay: TimeInterval = 60 * 60 * 24
|
||||
isOlderThanADay = Date().timeIntervalSince(asDate) >= aDay
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
|
Loading…
Reference in New Issue
Block a user