From 9df1bdaceeabe0d3ab3a52c137136c90c9f88c0e Mon Sep 17 00:00:00 2001 From: Sergey Kazakov Date: Wed, 5 May 2021 13:05:34 +0300 Subject: [PATCH] any codable dates fix --- .../xcschemes/vapor-rest-kit.xcscheme | 98 +++++++++++++++++++ .../Utils/AnyCodable/AnyCodable.swift | 2 + .../Utils/AnyCodable/AnyDecodable.swift | 4 + .../Utils/AnyCodable/AnyEncodable.swift | 6 ++ 4 files changed, 110 insertions(+) create mode 100644 .swiftpm/xcode/xcshareddata/xcschemes/vapor-rest-kit.xcscheme diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/vapor-rest-kit.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/vapor-rest-kit.xcscheme new file mode 100644 index 0000000..1340255 --- /dev/null +++ b/.swiftpm/xcode/xcshareddata/xcschemes/vapor-rest-kit.xcscheme @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/VaporRestKit/Utils/AnyCodable/AnyCodable.swift b/Sources/VaporRestKit/Utils/AnyCodable/AnyCodable.swift index b331bb5..a8cb0ba 100755 --- a/Sources/VaporRestKit/Utils/AnyCodable/AnyCodable.swift +++ b/Sources/VaporRestKit/Utils/AnyCodable/AnyCodable.swift @@ -58,6 +58,8 @@ extension AnyCodable: Equatable { return lhs == rhs case let (lhs as String, rhs as String): return lhs == rhs + case let (lhs as Date, rhs as Date): + return lhs == rhs case (let lhs as [String: AnyCodable], let rhs as [String: AnyCodable]): return lhs == rhs case (let lhs as [AnyCodable], let rhs as [AnyCodable]): diff --git a/Sources/VaporRestKit/Utils/AnyCodable/AnyDecodable.swift b/Sources/VaporRestKit/Utils/AnyCodable/AnyDecodable.swift index d4d6c80..b72a8ef 100755 --- a/Sources/VaporRestKit/Utils/AnyCodable/AnyDecodable.swift +++ b/Sources/VaporRestKit/Utils/AnyCodable/AnyDecodable.swift @@ -61,6 +61,8 @@ extension _AnyDecodable { self.init(double) } else if let string = try? container.decode(String.self) { self.init(string) + } else if let date = try? container.decode(Date.self) { + self.init(date) } else if let array = try? container.decode([AnyCodable].self) { self.init(array.map { $0.value }) } else if let dictionary = try? container.decode([String: AnyCodable].self) { @@ -106,6 +108,8 @@ extension AnyDecodable: Equatable { return lhs == rhs case let (lhs as String, rhs as String): return lhs == rhs + case let (lhs as Date, rhs as Date): + return lhs == rhs case (let lhs as [String: AnyDecodable], let rhs as [String: AnyDecodable]): return lhs == rhs case (let lhs as [AnyDecodable], let rhs as [AnyDecodable]): diff --git a/Sources/VaporRestKit/Utils/AnyCodable/AnyEncodable.swift b/Sources/VaporRestKit/Utils/AnyCodable/AnyEncodable.swift index 114067a..b226130 100755 --- a/Sources/VaporRestKit/Utils/AnyCodable/AnyEncodable.swift +++ b/Sources/VaporRestKit/Utils/AnyCodable/AnyEncodable.swift @@ -131,6 +131,8 @@ extension AnyEncodable: Equatable { return lhs == rhs case let (lhs as String, rhs as String): return lhs == rhs + case let (lhs as Date, rhs as Date): + return lhs == rhs case (let lhs as [String: AnyEncodable], let rhs as [String: AnyEncodable]): return lhs == rhs case (let lhs as [AnyEncodable], let rhs as [AnyEncodable]): @@ -196,6 +198,10 @@ extension _AnyEncodable { self.init(value) } + init(dateLiteral value: Date) { + self.init(value) + } + init(arrayLiteral elements: Any...) { self.init(elements) }