Skip to content

Instantly share code, notes, and snippets.

@turekj
Created January 8, 2020 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save turekj/da30393e7b9fbc310e67a37b22676bbb to your computer and use it in GitHub Desktop.
Save turekj/da30393e7b9fbc310e67a37b22676bbb to your computer and use it in GitHub Desktop.
Supplementary test helper code for https://jakubturek.com/bottom-up-unit-testing/
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