Created
October 8, 2020 15:45
-
-
Save tritchey/a23dc21afca932ddaec0fdc41dd0de7d 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
class ISO8601OptionalFractionalSecondsDateFormatter: ISO8601DateFormatter { | |
static let withoutFractionalSeconds = ISO8601DateFormatter() | |
func setup() { | |
formatOptions = [.withInternetDateTime, .withFractionalSeconds] | |
} | |
override init() { | |
super.init() | |
setup() | |
} | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
setup() | |
} | |
override func date(from string: String) -> Date? { | |
if let result = super.date(from: string) { | |
return result | |
} | |
return ISO8601OptionalFractionalSecondsDateFormatter.withoutFractionalSeconds.date(from: string) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment