Addressed a ISO date+time decoding issue inside the "decode(_:)" method for the ISOTimestampTranscoder transcoder in the library target.
This commit is contained in:
@@ -40,9 +40,17 @@ extension ISOTimestampTranscoder: DateTranscoder {
|
|||||||
|
|
||||||
/// Decodes an ISO timestamp string into a date.
|
/// Decodes an ISO timestamp string into a date.
|
||||||
/// - Parameter string: A string to decode.
|
/// - Parameter string: A string to decode.
|
||||||
/// - Returns: A date parsed from the string, or the Unix epoch if the string cannot be parsed.
|
/// - Returns: A date parsed from the string.
|
||||||
|
/// - Throws: A `DecodingError` if the string cannot be parsed into a valid date.
|
||||||
func decode(_ string: String) throws -> Date {
|
func decode(_ string: String) throws -> Date {
|
||||||
dateFormatter.date(from: string) ?? .init()
|
guard let date = dateFormatter.date(from: string) else {
|
||||||
|
throw DecodingError.dataCorrupted(.init(
|
||||||
|
codingPath: [],
|
||||||
|
debugDescription: "Expected an ISO timestamp with format 'yyyy-MM-dd'T'HH:mm:ss.SSSSSS', but found '\(string)' instead."
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
return date
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user