Skip to content

Commit

Permalink
Merge pull request #560 from NordicSemiconductor/improvement/import-time
Browse files Browse the repository at this point in the history
Support for importing configuration with fractional seconds
  • Loading branch information
philips77 authored Oct 10, 2023
2 parents bf5c93a + 91ee626 commit 514587b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion nRFMeshProvision/MeshNetworkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 514587b

Please sign in to comment.