reworked gaurd statement

This commit is contained in:
Stuart Breckenridge 2021-04-13 12:17:31 +08:00
parent 307b24af1b
commit 7df2fa5b1e
No known key found for this signature in database
GPG Key ID: ED2F112EEA9EF8A5
1 changed files with 4 additions and 6 deletions

View File

@ -59,16 +59,14 @@ struct ArticleItemView: View {
func pubDate(_ dateString: String) -> String { func pubDate(_ dateString: String) -> String {
let dateFormatter = DateFormatter() let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss Z" 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() let displayFormatter = DateFormatter()
displayFormatter.dateStyle = .medium displayFormatter.dateStyle = .medium
displayFormatter.timeStyle = .none displayFormatter.timeStyle = .none
guard let dateFromDateFormatter = date else { return displayFormatter.string(from: date)
return ""
}
return displayFormatter.string(from: dateFromDateFormatter)
} }
} }