From 91ee6261af233a7fc6e82104458711ce620571f2 Mon Sep 17 00:00:00 2001 From: Aleksander Nowakowski Date: Tue, 10 Oct 2023 16:06:42 +0200 Subject: [PATCH] Support for importing configuration with fractional seconds --- nRFMeshProvision/MeshNetworkManager.swift | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/nRFMeshProvision/MeshNetworkManager.swift b/nRFMeshProvision/MeshNetworkManager.swift index d83f3ec5c..7c5f6845d 100644 --- a/nRFMeshProvision/MeshNetworkManager.swift +++ b/nRFMeshProvision/MeshNetworkManager.swift @@ -1252,7 +1252,19 @@ public extension MeshNetworkManager { /// the local Provisioner failed. func `import`(from data: Data) throws -> MeshNetwork { let decoder = JSONDecoder() - decoder.dateDecodingStrategy = .iso8601 + + // The .iso8601 decoding strategy does not support fractional seconds. + // decoder.dateDecodingStrategy = .iso8601 + + // Instead, use ISO8601DateFormatter. + decoder.dateDecodingStrategy = .custom { decoder in + let formatter = ISO8601DateFormatter() + formatter.formatOptions.insert(.withFractionalSeconds) + + let container = try decoder.singleValueContainer() + let value = try container.decode(String.self) + return formatter.date(from: value) ?? Date.distantPast + } let meshNetwork = try decoder.decode(MeshNetwork.self, from: data)