Skip to content

Instantly share code, notes, and snippets.

@bre7
Created September 8, 2016 20:37
Show Gist options
  • Save bre7/2f9c5685631fc191530901e363f5a9b6 to your computer and use it in GitHub Desktop.
Save bre7/2f9c5685631fc191530901e363f5a9b6 to your computer and use it in GitHub Desktop.
// Extension making ISO8601DateFormatter usable as an UnboxFormatter
extension ISO8601DateFormatter: UnboxFormatter {
public func format(unboxedValue: String) -> Date? {
return self.date(from: unboxedValue)
}
}
// Shim (extension not needed)
class ISO8601DateFormatter: DateFormatter {
override init() {
super.init()
self.locale = Locale(identifier: "en_US_POSIX")
self.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
self.timeZone = TimeZone(secondsFromGMT: 0)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder:aDecoder)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment