Use a single instance of date formatter

This commit is contained in:
Balazs Perlaki-Horvath 2025-04-18 23:22:13 +02:00
parent c8aa5f5275
commit 703e6e34eb

View File

@ -16,14 +16,18 @@
import Foundation
extension Date {
/// Format the current date the way as it would come from a server's Last-Modified header
/// - Returns: eg: Thu, 16 May 2024 11:38:20 GMT
func formatAsGMT() -> String {
private static let dateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss 'GMT'"
formatter.locale = Locale(identifier: "en_US")
formatter.timeZone = TimeZone(abbreviation: "GMT")
return formatter.string(from: self)
return formatter
}()
/// Format the current date the way as it would come from a server's Last-Modified header
/// - Returns: eg: Thu, 16 May 2024 11:38:20 GMT
func formatAsGMT() -> String {
Self.dateFormatter.string(from: self)
}
}