Created
January 8, 2020 15:52
-
-
Save turekj/da30393e7b9fbc310e67a37b22676bbb to your computer and use it in GitHub Desktop.
Supplementary test helper code for https://jakubturek.com/bottom-up-unit-testing/
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 String { | |
var date: Date { | |
let formatter = DateFormatter() | |
formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss" | |
guard let date = formatter.date(from: self) else { | |
fatalError("Cannot build a date from \(self) string") | |
} | |
return date | |
} | |
} | |
class DateFromStringSpec: QuickSpec { | |
override func spec() { | |
describe("String+Date") { | |
it("should return correct date for 1990-01-09 12:00:00") { | |
expect("1990-01-09 12:00:00".date) | |
== Date(timeIntervalSince1970: 631886400) | |
} | |
it("should return correct date for 2020-11-11 11:11:11") { | |
expect("2020-11-11 11:11:11".date) | |
== Date(timeIntervalSince1970: 1605093071) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment