From e7955b4e9481c81406202117af905c34a1593476 Mon Sep 17 00:00:00 2001 From: dankinsoid <30962149+dankinsoid@users.noreply.github.com> Date: Tue, 23 Jul 2024 00:28:23 +0400 Subject: [PATCH] 1.30.0 --- .../TokenRefresher/TokenCacheService.swift | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/Sources/SwiftAPIClient/Modifiers/TokenRefresher/TokenCacheService.swift b/Sources/SwiftAPIClient/Modifiers/TokenRefresher/TokenCacheService.swift index 4249372..335f1f7 100644 --- a/Sources/SwiftAPIClient/Modifiers/TokenRefresher/TokenCacheService.swift +++ b/Sources/SwiftAPIClient/Modifiers/TokenRefresher/TokenCacheService.swift @@ -42,12 +42,12 @@ public extension SecureCacheService where Self == MockSecureCacheService { public extension SecureCacheService { func save(_ date: Date?, for key: SecureCacheServiceKey) async throws { - try await save(date.map(dateFormatter.string), for: key) + try await save(date.map(DateFormatter.secureCacheService.string), for: key) } func load(for key: SecureCacheServiceKey) async throws -> Date? { guard let dateString = try await load(for: key) else { return nil } - return dateFormatter.date(from: dateString) + return DateFormatter.secureCacheService.date(from: dateString) } @_disfavoredOverload @@ -287,10 +287,14 @@ private final actor Holder { #endif #endif -private let dateFormatter: DateFormatter = { - let formatter = DateFormatter() - formatter.locale = Locale(identifier: "en_US_POSIX") - formatter.timeZone = TimeZone(secondsFromGMT: 0) - formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" - return formatter -}() +public extension DateFormatter { + + /// A date formatter for the secure cache service to format dates. + static let secureCacheService: DateFormatter = { + let formatter = DateFormatter() + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" + return formatter + }() +}