From 2ca8b65a57b1f7109ff9ef52aae9985f5b01908d Mon Sep 17 00:00:00 2001 From: "Artyom Y. Razinov" Date: Mon, 8 Apr 2024 16:45:33 +0300 Subject: [PATCH] Fix date parsing for certain environments There were 2 users (in a certain company where I work, which is a very small fraction of users) who experienced this issue, they had some specific environment, we did not check which environment they had or why this code works, we only know that it solves the issue --- Sources/APIProvider.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/APIProvider.swift b/Sources/APIProvider.swift index 47d1d7bd..d4a16d22 100644 --- a/Sources/APIProvider.swift +++ b/Sources/APIProvider.swift @@ -119,6 +119,12 @@ public final class APIProvider { if let date = formatter.date(from: dateStr) { return date } + // Example: 2024-01-01T23:59:59.000+00:00 + let isoDateFormatter = ISO8601DateFormatter() + isoDateFormatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds] + if let date = isoDateFormatter.date(from: dateStr) { + return date + } throw APIProvider.Error.dateDecodingError(dateStr) }) return decoder