From 1017dd34e19e3cd1cd7a9ac873fce8f65138b9af Mon Sep 17 00:00:00 2001 From: CMK Date: Mon, 9 Aug 2021 19:51:11 +0800 Subject: [PATCH] chore: update timestamp style --- Mastodon/Extension/Date.swift | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Mastodon/Extension/Date.swift b/Mastodon/Extension/Date.swift index 86288c216..183c3f5d9 100644 --- a/Mastodon/Extension/Date.swift +++ b/Mastodon/Extension/Date.swift @@ -18,22 +18,25 @@ extension Date { }() var localizedSlowedTimeAgoSinceNow: String { - return self.localizedTimeAgo(since: Date(), isSlowed: true) - + return self.localizedTimeAgo(since: Date(), isSlowed: true, isAbbreviated: true) } 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 latestDate = earlierDate == date ? self : date if isSlowed, earlierDate.timeIntervalSince(latestDate) >= -60 { return L10n.Common.Controls.Timeline.Timestamp.now } 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) + } } }