From 3cf55d91ff9b2e68bbe61042e7ca57676e1f471f Mon Sep 17 00:00:00 2001 From: Danny Moesch Date: Sun, 17 Feb 2019 11:51:14 +0100 Subject: [PATCH] Display last updated date in absolut instead of relative form This is necessary to have a language independent representation. For example, the previous format would have produced a grammatically wrong term in German. --- pass/en.lproj/Localizable.strings | 1 - passKit/Models/PasswordStore.swift | 22 ++++++++++------------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/pass/en.lproj/Localizable.strings b/pass/en.lproj/Localizable.strings index fc2b4eb..9969a74 100644 --- a/pass/en.lproj/Localizable.strings +++ b/pass/en.lproj/Localizable.strings @@ -154,7 +154,6 @@ // Time related "Unknown" = "Unknown"; "JustNow" = "Just now"; -"TimeAgo" = "%@ ago"; // Commit messages "AddPassword." = "Add password for %@ to store using Pass for iOS."; diff --git a/passKit/Models/PasswordStore.swift b/passKit/Models/PasswordStore.swift index b1cbe93..e80a053 100644 --- a/passKit/Models/PasswordStore.swift +++ b/passKit/Models/PasswordStore.swift @@ -16,6 +16,13 @@ import KeychainAccess public class PasswordStore { public static let shared = PasswordStore() + private static let dateFormatter: DateFormatter = { + let dateFormatter = DateFormatter() + dateFormatter.dateStyle = .short + dateFormatter.timeStyle = .short + return dateFormatter + }() + public let storeURL = URL(fileURLWithPath: "\(Globals.repositoryPath)") public let tempStoreURL = URL(fileURLWithPath: "\(Globals.repositoryPath)-temp") @@ -499,19 +506,10 @@ public class PasswordStore { return "Unknown".localize() } let lastCommitDate = Date(timeIntervalSince1970: latestCommitTime) - let currentDate = Date() - var autoFormattedDifference: String - if currentDate.timeIntervalSince(lastCommitDate) <= 60 { - autoFormattedDifference = "JustNow".localize() - } else { - let diffDate = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute], from: lastCommitDate, to: currentDate) - let dateComponentsFormatter = DateComponentsFormatter() - dateComponentsFormatter.unitsStyle = .full - dateComponentsFormatter.maximumUnitCount = 2 - dateComponentsFormatter.includesApproximationPhrase = true - autoFormattedDifference = "TimeAgo".localize(dateComponentsFormatter.string(from: diffDate)!) + if Date().timeIntervalSince(lastCommitDate) <= 60 { + return "JustNow".localize() } - return autoFormattedDifference + return PasswordStore.dateFormatter.string(from: lastCommitDate) } public func updateRemoteRepo() {