Created
November 18, 2017 20:24
-
-
Save diederich/3cb8e648f9cce597f65a709f6e8fc988 to your computer and use it in GitHub Desktop.
Date Formatting Debug Helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Debug helper for date parsing | |
/// add via decoder.dateDecodingStrategy = .custom(customDateFormatter) | |
func customDateFormatter(_ decoder: Decoder) throws -> Date { | |
let dateString = try decoder.singleValueContainer().decode(String.self) | |
let formatter = DateFormatter() | |
formatter.dateFormat = "YYYY-MM-DD'T'HH:mm:ss.SSSZ" | |
let date = formatter.date(from: dateString) | |
print("Asked to parse date: \(dateString) and got: \(date?.description ?? "-")") | |
return date ?? Date() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment