mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-24 01:01:00 +00:00
Parse dates without fractional seconds
This commit is contained in:
parent
7296de1dba
commit
8ceb02ba35
1 changed files with 10 additions and 1 deletions
|
@ -11,7 +11,8 @@ public final class MastodonDecoder: JSONDecoder {
|
|||
let container = try decoder.singleValueContainer()
|
||||
let dateString = try container.decode(String.self)
|
||||
|
||||
guard let date = Self.dateFormatter.date(from: dateString) else {
|
||||
guard let date = Self.dateFormatter.date(from: dateString)
|
||||
?? Self.dateFormatterWithoutFractionalSeconds.date(from: dateString) else {
|
||||
throw DecodingError.dataCorruptedError(in: container, debugDescription: "Unable to parse ISO8601 date")
|
||||
}
|
||||
|
||||
|
@ -28,4 +29,12 @@ public extension MastodonDecoder {
|
|||
|
||||
return dateFormatter
|
||||
}()
|
||||
|
||||
static let dateFormatterWithoutFractionalSeconds: ISO8601DateFormatter = {
|
||||
let dateFormatter = ISO8601DateFormatter()
|
||||
|
||||
dateFormatter.formatOptions = [.withInternetDateTime]
|
||||
|
||||
return dateFormatter
|
||||
}()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue