From 307b24af1bf65a263d44abb1012cdf15d7662bc1 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Tue, 13 Apr 2021 12:00:50 +0800 Subject: [PATCH 1/2] Fixes #2994 Removes force unwrapping and returns an empty string if the pubDate cannot be determined. --- Widget/Shared Views/ArticleItemView.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Widget/Shared Views/ArticleItemView.swift b/Widget/Shared Views/ArticleItemView.swift index a35f07826..455cbaaf9 100644 --- a/Widget/Shared Views/ArticleItemView.swift +++ b/Widget/Shared Views/ArticleItemView.swift @@ -65,6 +65,10 @@ struct ArticleItemView: View { displayFormatter.dateStyle = .medium displayFormatter.timeStyle = .none - return displayFormatter.string(from: date!) + guard let dateFromDateFormatter = date else { + return "" + } + + return displayFormatter.string(from: dateFromDateFormatter) } } From 7df2fa5b1e686e58cd619a44139503142b690457 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Tue, 13 Apr 2021 12:17:31 +0800 Subject: [PATCH 2/2] reworked gaurd statement --- Widget/Shared Views/ArticleItemView.swift | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Widget/Shared Views/ArticleItemView.swift b/Widget/Shared Views/ArticleItemView.swift index 455cbaaf9..c3ed7467d 100644 --- a/Widget/Shared Views/ArticleItemView.swift +++ b/Widget/Shared Views/ArticleItemView.swift @@ -59,16 +59,14 @@ struct ArticleItemView: View { func pubDate(_ dateString: String) -> String { let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss Z" - let date = dateFormatter.date(from: dateString) + guard let date = dateFormatter.date(from: dateString) else { + return "" + } let displayFormatter = DateFormatter() displayFormatter.dateStyle = .medium displayFormatter.timeStyle = .none - guard let dateFromDateFormatter = date else { - return "" - } - - return displayFormatter.string(from: dateFromDateFormatter) + return displayFormatter.string(from: date) } }