From 4d9078c9768da45ad15509581f2ddb1287cf9528 Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 27 Apr 2026 17:33:14 +0800 Subject: [PATCH] fix: exclude .formatted date strategy case on Linux On Linux, swift-foundation (FoundationEssentials) does not define .formatted as an enum case on DateEncodingStrategy/DateDecodingStrategy. Instead, swift-corelibs-foundation provides a static func .formatted() that returns .custom(...), so the .custom case already handles it. Closes #7 Made-with: Cursor --- Sources/ReerJSON/JSONDecoderImpl.swift | 2 ++ Sources/ReerJSON/JSONEncoderImpl.swift | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Sources/ReerJSON/JSONDecoderImpl.swift b/Sources/ReerJSON/JSONDecoderImpl.swift index b28cb01..0235414 100644 --- a/Sources/ReerJSON/JSONDecoderImpl.swift +++ b/Sources/ReerJSON/JSONDecoderImpl.swift @@ -267,6 +267,7 @@ final class JSONDecoderImpl: Decoder { )) } return date + #if !os(Linux) case .formatted(let formatter): let string = try unboxString(from: value, for: codingPathNode, additionalKey) guard let date = formatter.date(from: string) else { @@ -276,6 +277,7 @@ final class JSONDecoderImpl: Decoder { )) } return date + #endif case .custom(let closure): return try with(value: value, path: codingPathNode.appending(additionalKey)) { try closure(self) diff --git a/Sources/ReerJSON/JSONEncoderImpl.swift b/Sources/ReerJSON/JSONEncoderImpl.swift index 87a3368..16ae041 100644 --- a/Sources/ReerJSON/JSONEncoderImpl.swift +++ b/Sources/ReerJSON/JSONEncoderImpl.swift @@ -283,8 +283,10 @@ class JSONEncoderImpl: Encoder { return try wrapFloat(1000.0 * date.timeIntervalSince1970, for: additionalKey) case .iso8601: return wrapString(_iso8601Formatter.string(from: date)) + #if !os(Linux) case .formatted(let formatter): return wrapString(formatter.string(from: date)) + #endif case .custom(let closure): return try _encodeNestedValue(for: additionalKey) { try closure(date, self) } ?? yyjson_mut_obj(doc) @unknown default: fatalError()