Skip to content

Commit a0a17ae

Browse files
authored
Get rid of global iso8601 formatter (#274)
1 parent d7fb66e commit a0a17ae

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

Sources/HummingbirdFoundation/Codable/URLEncodedForm/URLEncodedForm.swift

-8
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,4 @@ internal enum URLEncodedForm {
4545

4646
/// ASCII characters that will not be percent encoded in URL encoded form data
4747
static let unreservedCharacters = CharacterSet(charactersIn: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~")
48-
49-
@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
50-
/// ISO8601 data formatter used throughout URL encoded form code
51-
static var iso8601Formatter: ISO8601DateFormatter = {
52-
let formatter = ISO8601DateFormatter()
53-
formatter.formatOptions = .withInternetDateTime
54-
return formatter
55-
}()
5648
}

Sources/HummingbirdFoundation/Codable/URLEncodedForm/URLEncodedFormDecoder.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,10 @@ extension _URLEncodedFormDecoder {
590590
return Date(timeIntervalSince1970: seconds)
591591
case .iso8601:
592592
if #available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
593+
let iso8601Formatter = ISO8601DateFormatter()
594+
iso8601Formatter.formatOptions = .withInternetDateTime
593595
let dateString = try unbox(node, as: String.self)
594-
guard let date = URLEncodedForm.iso8601Formatter.date(from: dateString) else {
596+
guard let date = iso8601Formatter.date(from: dateString) else {
595597
throw DecodingError.dataCorrupted(.init(codingPath: self.codingPath, debugDescription: "Invalid date format"))
596598
}
597599
return date

Sources/HummingbirdFoundation/Codable/URLEncodedForm/URLEncodedFormEncoder.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,9 @@ extension _URLEncodedFormEncoder {
324324
try self.encode(Double(date.timeIntervalSince1970).description)
325325
case .iso8601:
326326
if #available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
327-
try encode(URLEncodedForm.iso8601Formatter.string(from: date))
327+
let iso8601Formatter = ISO8601DateFormatter()
328+
iso8601Formatter.formatOptions = .withInternetDateTime
329+
try encode(iso8601Formatter.string(from: date))
328330
} else {
329331
preconditionFailure("ISO8601DateFormatter is unavailable on this platform")
330332
}

0 commit comments

Comments
 (0)