diff --git a/Mastodon/Sources/Mastodon/Coding/MastodonDecoder.swift b/Mastodon/Sources/Mastodon/Coding/MastodonDecoder.swift index 78737d9..0eaf857 100644 --- a/Mastodon/Sources/Mastodon/Coding/MastodonDecoder.swift +++ b/Mastodon/Sources/Mastodon/Coding/MastodonDecoder.swift @@ -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 + }() }