Use relative time format for Last Updated

This commit is contained in:
世界
2025-12-06 22:27:42 +08:00
parent dcc6cd189c
commit bd5e5f3a79
5 changed files with 12 additions and 6 deletions
@@ -348,7 +348,7 @@ public struct ProfileCard: View {
Image(systemName: "clock.fill") Image(systemName: "clock.fill")
.font(.system(size: 12)) .font(.system(size: 12))
.foregroundColor(.secondary) .foregroundColor(.secondary)
Text(lastUpdated.myFormat) Text(lastUpdated.relativeFormat)
.font(.caption) .font(.caption)
.foregroundColor(.primary) .foregroundColor(.primary)
} }
@@ -892,7 +892,7 @@ private struct ProfilePickerRow: View {
Image(systemName: "clock.fill") Image(systemName: "clock.fill")
.font(.system(size: 12)) .font(.system(size: 12))
.foregroundStyle(.secondary) .foregroundStyle(.secondary)
Text(lastUpdated.myFormat) Text(lastUpdated.relativeFormat)
.font(.caption) .font(.caption)
.foregroundStyle(.secondary) .foregroundStyle(.secondary)
} }
@@ -947,7 +947,7 @@ private struct ProfilePickerRow: View {
Image(systemName: "clock.fill") Image(systemName: "clock.fill")
.font(.system(size: 12)) .font(.system(size: 12))
.foregroundStyle(.secondary) .foregroundStyle(.secondary)
Text(lastUpdated.myFormat) Text(lastUpdated.relativeFormat)
.font(.caption) .font(.caption)
.foregroundStyle(.secondary) .foregroundStyle(.secondary)
} }
@@ -1155,7 +1155,7 @@ private struct ProfilePickerRow: View {
Image(systemName: "clock.fill") Image(systemName: "clock.fill")
.font(.system(size: 12)) .font(.system(size: 12))
.foregroundStyle(.secondary) .foregroundStyle(.secondary)
Text(lastUpdated.myFormat) Text(lastUpdated.relativeFormat)
.font(.caption) .font(.caption)
.foregroundStyle(.secondary) .foregroundStyle(.secondary)
} }
@@ -61,7 +61,7 @@ public struct EditProfileView: View {
} }
if profile.type == .remote { if profile.type == .remote {
Section("Status") { Section("Status") {
FormTextItem("Last Updated", profile.lastUpdated!.myFormat) FormTextItem("Last Updated", profile.lastUpdated!.relativeFormat)
} }
} }
@@ -230,7 +230,7 @@ public struct ProfileView: View {
Text(profile.name) Text(profile.name)
if profile.type == .remote { if profile.type == .remote {
Spacer(minLength: 4) Spacer(minLength: 4)
Text("Last Updated: \(profile.origin.lastUpdated!.myFormat)").font(.caption) Text("Last Updated: \(profile.origin.lastUpdated!.relativeFormat)").font(.caption)
} }
} }
HStack { HStack {
+6
View File
@@ -6,4 +6,10 @@ public extension Date {
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
return dateFormatter.string(from: self) return dateFormatter.string(from: self)
} }
var relativeFormat: String {
let formatter = RelativeDateTimeFormatter()
formatter.unitsStyle = .full
return formatter.localizedString(for: self, relativeTo: Date())
}
} }