diff options
| author | Dustin Mierau <dustin@mierau.me> | 2023-12-20 12:47:09 -0800 |
|---|---|---|
| committer | Dustin Mierau <dustin@mierau.me> | 2023-12-20 12:47:09 -0800 |
| commit | cc19df82bab213bd628792e0b3eca8c2ee986506 (patch) | |
| tree | 43c8f6da30a59bb363428e63b42c97d40179a0d3 /Hotline | |
| parent | 174e5554fc55f19b36b9fa3a3155d27ef918141d (diff) | |
Add relative dates to news list on macOS. Also add full date/time display in news reader view.
Diffstat (limited to 'Hotline')
| -rw-r--r-- | Hotline/macOS/NewsView.swift | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/Hotline/macOS/NewsView.swift b/Hotline/macOS/NewsView.swift index aa32d6a..c59b446 100644 --- a/Hotline/macOS/NewsView.swift +++ b/Hotline/macOS/NewsView.swift @@ -11,11 +11,20 @@ struct NewsItemView: View { static var dateFormatter: DateFormatter = { var dateFormatter = DateFormatter() - dateFormatter.dateFormat = "MM/dd/yy, h:mm a" + dateFormatter.dateStyle = .long + dateFormatter.timeStyle = .short dateFormatter.timeZone = .gmt return dateFormatter }() + static var relativeDateFormatter: RelativeDateTimeFormatter = { + var formatter = RelativeDateTimeFormatter() + formatter.unitsStyle = .full + formatter.dateTimeStyle = .named + formatter.formattingContext = .listItem + return formatter + }() + var body: some View { HStack { if news.type == .bundle || news.type == .category { @@ -44,6 +53,7 @@ struct NewsItemView: View { if news.type == .article && news.articleUsername != nil { Text(news.articleUsername!).foregroundStyle(.secondary).lineLimit(1) } + Spacer() if news.type == .bundle || news.type == .category { Text("^[\(news.count) \(news.type == .bundle ? "Category" : "Post")](inflect: true)") @@ -54,10 +64,9 @@ struct NewsItemView: View { .padding([.top, .bottom], 2) .background(Capsule(style: .circular).stroke(.secondary.opacity(0.3), lineWidth: 1)) } - Spacer() if news.type == .article && news.articleUsername != nil { if let d = news.articleDate { - Text(NewsItemView.dateFormatter.string(from: d)).foregroundStyle(.secondary) + Text(NewsItemView.relativeDateFormatter.localizedString(for: d, relativeTo: Date.now)).lineLimit(1).foregroundStyle(.secondary) } } } |