You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if #available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0,*){
176
+
letstring=try container.decode(String.self)
177
+
guardlet date = _iso8601Formatter.date(from: string)else{
178
+
throwDecodingError.dataCorrupted(DecodingError.Context(codingPath:self.codingPath, debugDescription:"Expected date string to be ISO8601-formatted."))
179
+
}
180
+
181
+
return date
182
+
}else{
183
+
fatalError("ISO8601DateFormatter is unavailable on this platform.")
179
184
}
180
185
186
+
case.formatted(let formatter):
187
+
letstring=try container.decode(String.self)
188
+
guardlet date = formatter.date(from: string)else{
189
+
throwDecodingError.dataCorrupted(DecodingError.Context(codingPath:self.codingPath, debugDescription:"Date string does not match format expected by formatter."))
190
+
}
181
191
return date
182
-
}else{
183
-
fatalError("ISO8601DateFormatter is unavailable on this platform.")
throwDecodingError.dataCorrupted(DecodingError.Context(codingPath:self.codingPath, debugDescription:"Date string does not match format expected by formatter."))
192
+
193
+
case.custom(let closure):
194
+
returntryclosure(self)
195
+
@unknowndefault:
196
+
throwDecodingError.dataCorrupted(DecodingError.Context(codingPath:self.codingPath, debugDescription:"Encountered Date is not valid , unknown anomaly"))
191
197
}
198
+
}
199
+
200
+
// 如果没有设置策略,使用 DateParser 做兜底解析
201
+
iflet(date, _)=DateParser.parse(json.peel){
192
202
return date
193
-
194
-
case.custom(let closure):
195
-
returntryclosure(self)
196
-
@unknowndefault:
197
-
throwDecodingError.dataCorrupted(DecodingError.Context(codingPath:self.codingPath, debugDescription:"Encountered Date is not valid , unknown anomaly"))
203
+
}else{
204
+
throwDecodingError.dataCorrupted(.init(codingPath: codingPath, debugDescription:"Unsupported date format: \(json)"))
0 commit comments