Handle UNIX timestamps in String.swiftyDate() method

This commit is contained in:
Caleb Kleveter 2019-05-02 15:02:52 -05:00
parent 0b13457b82
commit 161946cb6c
No known key found for this signature in database
GPG Key ID: B38DBD5CF2C98D69
1 changed files with 4 additions and 0 deletions

View File

@ -50,6 +50,10 @@ extension String {
} }
public func swiftyDate(calendar:Calendar = Calendar.current) -> Date? { public func swiftyDate(calendar:Calendar = Calendar.current) -> Date? {
if let timestamp = TimeInterval(self) {
return Date(timeIntervalSince1970: timestamp)
}
// is this even a string we can work with? // is this even a string we can work with?
if (self.count < 1) { return nil } if (self.count < 1) { return nil }