Created
September 8, 2016 20:37
-
-
Save bre7/2f9c5685631fc191530901e363f5a9b6 to your computer and use it in GitHub Desktop.
This file contains 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
// 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