chore: update timestamp style

This commit is contained in:
CMK 2021-08-09 19:51:11 +08:00
parent ddd1d0f6e4
commit 1017dd34e1
1 changed files with 8 additions and 5 deletions

View File

@ -18,22 +18,25 @@ extension Date {
}() }()
var localizedSlowedTimeAgoSinceNow: String { var localizedSlowedTimeAgoSinceNow: String {
return self.localizedTimeAgo(since: Date(), isSlowed: true) return self.localizedTimeAgo(since: Date(), isSlowed: true, isAbbreviated: true)
} }
var localizedTimeAgoSinceNow: String { var localizedTimeAgoSinceNow: String {
return self.localizedTimeAgo(since: Date(), isSlowed: false) return self.localizedTimeAgo(since: Date(), isSlowed: false, isAbbreviated: false)
} }
func localizedTimeAgo(since date: Date, isSlowed: Bool) -> String { func localizedTimeAgo(since date: Date, isSlowed: Bool, isAbbreviated: Bool) -> String {
let earlierDate = date < self ? date : self let earlierDate = date < self ? date : self
let latestDate = earlierDate == date ? self : date let latestDate = earlierDate == date ? self : date
if isSlowed, earlierDate.timeIntervalSince(latestDate) >= -60 { if isSlowed, earlierDate.timeIntervalSince(latestDate) >= -60 {
return L10n.Common.Controls.Timeline.Timestamp.now return L10n.Common.Controls.Timeline.Timestamp.now
} else { } else {
return Date.relativeTimestampFormatter.localizedString(for: earlierDate, relativeTo: latestDate) if isAbbreviated {
return latestDate.shortTimeAgo(since: earlierDate)
} else {
return Date.relativeTimestampFormatter.localizedString(for: earlierDate, relativeTo: latestDate)
}
} }
} }