From bd5e5f3a790dc528bf9b68801967efc260c20f3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sat, 6 Dec 2025 22:27:42 +0800 Subject: [PATCH] Use relative time format for Last Updated --- ApplicationLibrary/Views/Dashboard/Cards/ProfileCard.swift | 2 +- .../Views/Dashboard/Cards/ProfilePickerSheet.swift | 6 +++--- ApplicationLibrary/Views/Profile/EditProfileView.swift | 2 +- ApplicationLibrary/Views/Profile/ProfileView.swift | 2 +- Library/Database/Profile+Date.swift | 6 ++++++ 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ApplicationLibrary/Views/Dashboard/Cards/ProfileCard.swift b/ApplicationLibrary/Views/Dashboard/Cards/ProfileCard.swift index af988ab..0d770c8 100644 --- a/ApplicationLibrary/Views/Dashboard/Cards/ProfileCard.swift +++ b/ApplicationLibrary/Views/Dashboard/Cards/ProfileCard.swift @@ -348,7 +348,7 @@ public struct ProfileCard: View { Image(systemName: "clock.fill") .font(.system(size: 12)) .foregroundColor(.secondary) - Text(lastUpdated.myFormat) + Text(lastUpdated.relativeFormat) .font(.caption) .foregroundColor(.primary) } diff --git a/ApplicationLibrary/Views/Dashboard/Cards/ProfilePickerSheet.swift b/ApplicationLibrary/Views/Dashboard/Cards/ProfilePickerSheet.swift index 33a0f72..9395143 100644 --- a/ApplicationLibrary/Views/Dashboard/Cards/ProfilePickerSheet.swift +++ b/ApplicationLibrary/Views/Dashboard/Cards/ProfilePickerSheet.swift @@ -892,7 +892,7 @@ private struct ProfilePickerRow: View { Image(systemName: "clock.fill") .font(.system(size: 12)) .foregroundStyle(.secondary) - Text(lastUpdated.myFormat) + Text(lastUpdated.relativeFormat) .font(.caption) .foregroundStyle(.secondary) } @@ -947,7 +947,7 @@ private struct ProfilePickerRow: View { Image(systemName: "clock.fill") .font(.system(size: 12)) .foregroundStyle(.secondary) - Text(lastUpdated.myFormat) + Text(lastUpdated.relativeFormat) .font(.caption) .foregroundStyle(.secondary) } @@ -1155,7 +1155,7 @@ private struct ProfilePickerRow: View { Image(systemName: "clock.fill") .font(.system(size: 12)) .foregroundStyle(.secondary) - Text(lastUpdated.myFormat) + Text(lastUpdated.relativeFormat) .font(.caption) .foregroundStyle(.secondary) } diff --git a/ApplicationLibrary/Views/Profile/EditProfileView.swift b/ApplicationLibrary/Views/Profile/EditProfileView.swift index d8878fc..5bff51f 100644 --- a/ApplicationLibrary/Views/Profile/EditProfileView.swift +++ b/ApplicationLibrary/Views/Profile/EditProfileView.swift @@ -61,7 +61,7 @@ public struct EditProfileView: View { } if profile.type == .remote { Section("Status") { - FormTextItem("Last Updated", profile.lastUpdated!.myFormat) + FormTextItem("Last Updated", profile.lastUpdated!.relativeFormat) } } diff --git a/ApplicationLibrary/Views/Profile/ProfileView.swift b/ApplicationLibrary/Views/Profile/ProfileView.swift index d440bd0..1ffa015 100644 --- a/ApplicationLibrary/Views/Profile/ProfileView.swift +++ b/ApplicationLibrary/Views/Profile/ProfileView.swift @@ -230,7 +230,7 @@ public struct ProfileView: View { Text(profile.name) if profile.type == .remote { Spacer(minLength: 4) - Text("Last Updated: \(profile.origin.lastUpdated!.myFormat)").font(.caption) + Text("Last Updated: \(profile.origin.lastUpdated!.relativeFormat)").font(.caption) } } HStack { diff --git a/Library/Database/Profile+Date.swift b/Library/Database/Profile+Date.swift index 0486a7c..866370d 100644 --- a/Library/Database/Profile+Date.swift +++ b/Library/Database/Profile+Date.swift @@ -6,4 +6,10 @@ public extension Date { dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" return dateFormatter.string(from: self) } + + var relativeFormat: String { + let formatter = RelativeDateTimeFormatter() + formatter.unitsStyle = .full + return formatter.localizedString(for: self, relativeTo: Date()) + } }