Use relative time to present last updated time
This commit is contained in:
parent
98b01d16cf
commit
8798be65b5
2 changed files with 18 additions and 7 deletions
|
|
@ -338,16 +338,27 @@ class PasswordStore {
|
|||
}
|
||||
}
|
||||
|
||||
func getLatestCommitDate(filename: String) -> String? {
|
||||
func getLatestUpdateInfo(filename: String) -> String {
|
||||
guard let blameHunks = try? storeRepository?.blame(withFile: filename, options: nil).hunks,
|
||||
let latestCommitTime = blameHunks?.map({
|
||||
$0.finalSignature?.time?.timeIntervalSince1970 ?? 0
|
||||
}).max() else {
|
||||
return nil
|
||||
return "unknown"
|
||||
}
|
||||
let date = Date(timeIntervalSince1970: latestCommitTime)
|
||||
let dateString = DateFormatter.localizedString(from: date, dateStyle: DateFormatter.Style.medium, timeStyle: DateFormatter.Style.medium)
|
||||
return dateString
|
||||
let lastCommitDate = Date(timeIntervalSince1970: latestCommitTime)
|
||||
let currentDate = Date()
|
||||
var autoFormattedDifference: String
|
||||
if currentDate.timeIntervalSince(lastCommitDate) <= 60 {
|
||||
autoFormattedDifference = "just now"
|
||||
} 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 = (dateComponentsFormatter.string(from: diffDate)?.appending(" ago"))!
|
||||
}
|
||||
return autoFormattedDifference
|
||||
}
|
||||
|
||||
func updateRemoteRepo() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue