Skip to content

Instantly share code, notes, and snippets.

@diederich
Created November 18, 2017 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diederich/3cb8e648f9cce597f65a709f6e8fc988 to your computer and use it in GitHub Desktop.
Save diederich/3cb8e648f9cce597f65a709f6e8fc988 to your computer and use it in GitHub Desktop.
Date Formatting Debug Helper
/// 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