import Foundation

extension JSONDecoder.DateDecodingStrategy {
    static let formatter: DateFormatter = {
        var formatter = DateFormatter()
        //2021-11-01T11:45:24
        formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
        return formatter
    }()
    
    static let riot = custom {
        let container = try $0.singleValueContainer()
        let string = try container.decode(String.self)
        guard let date = formatter.date(from: string) else {
            throw DecodingError.dataCorruptedError(in: container,
                  debugDescription: "Invalid date: " + string)
        }
        return date
    }
}
