Skip to content

Commit

Permalink
add date decoding strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
radmakr committed Nov 14, 2023
1 parent a8e0004 commit 27bc80f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 6 additions & 2 deletions Sources/PodcastIndexKit/Networking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import Foundation
import CryptoKit

extension JSONDecoder {
static var podcastIndexDecoder: JSONDecoder {
static var podcastIndexDecoder: JSONDecoder {
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase

// TODO: need to encode and decode dates in this format - "2023-05-19T09:13:38-0500"
decoder.dateDecodingStrategy = .custom { decoder in
let container = try decoder.singleValueContainer()
let timestampInSeconds = try container.decode(Int.self)
return Date(timeIntervalSince1970: TimeInterval(timestampInSeconds))
}

return decoder
}
Expand Down
1 change: 0 additions & 1 deletion Sources/PodcastIndexKit/Services/SearchService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,3 @@ extension SearchAPI: EndpointType {
nil
}
}

0 comments on commit 27bc80f

Please sign in to comment.