From 703e6e34ebc2d1cc6ed7cec0df39204a4b7fc900 Mon Sep 17 00:00:00 2001 From: Balazs Perlaki-Horvath Date: Fri, 18 Apr 2025 23:22:13 +0200 Subject: [PATCH] Use a single instance of date formatter --- Model/Utilities/Date+Extension.swift | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Model/Utilities/Date+Extension.swift b/Model/Utilities/Date+Extension.swift index 3b45c90b..7cf54f2c 100644 --- a/Model/Utilities/Date+Extension.swift +++ b/Model/Utilities/Date+Extension.swift @@ -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) } }