From f9d60bd23f020381fa37471ddfe4bdc4cb0afacd Mon Sep 17 00:00:00 2001 From: Phan Anh Tran Date: Mon, 30 Sep 2024 08:58:49 +0100 Subject: [PATCH] Fixed issue with case .formatted of DateFormatter on Linux (swift 6) --- Sources/IkigaJSON/Codable/JSONDecoder.swift | 2 ++ Sources/IkigaJSON/Codable/JSONEncoder.swift | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Sources/IkigaJSON/Codable/JSONDecoder.swift b/Sources/IkigaJSON/Codable/JSONDecoder.swift index cc4f02e..1281234 100644 --- a/Sources/IkigaJSON/Codable/JSONDecoder.swift +++ b/Sources/IkigaJSON/Codable/JSONDecoder.swift @@ -262,6 +262,7 @@ fileprivate struct _JSONDecoder: Decoder { let string = try singleValueContainer().decode(String.self) return try date(from: string) as! D + #if !canImport(FoundationEssentials) || swift(<5.10) case .formatted(let formatter): let string = try singleValueContainer().decode(String.self) @@ -270,6 +271,7 @@ fileprivate struct _JSONDecoder: Decoder { } return date as! D + #endif case .custom(let makeDate): return try makeDate(self) as! D @unknown default: diff --git a/Sources/IkigaJSON/Codable/JSONEncoder.swift b/Sources/IkigaJSON/Codable/JSONEncoder.swift index 591eb36..1a6d2d0 100644 --- a/Sources/IkigaJSON/Codable/JSONEncoder.swift +++ b/Sources/IkigaJSON/Codable/JSONEncoder.swift @@ -386,12 +386,14 @@ fileprivate final class _JSONEncoder: Encoder { key.map { writeKey($0) } writeValue(string) + #if !canImport(FoundationEssentials) || swift(<5.10) case .formatted(let formatter): let string = formatter.string(from: date) if let key = key { writeKey(key) } writeValue(string) + #endif case .custom(let custom): let offsetBeforeKey = offset, hadWrittenValue = didWriteValue if let key = key {