@@ -546,6 +546,28 @@ class PostgreSQLConnectionTests: XCTestCase {
546
546
. run ( decoding: Planet . self) . wait ( )
547
547
XCTAssertNotEqual ( planetsA, planetsB)
548
548
}
549
+
550
+ // https://github.com/vapor/postgresql/issues/53
551
+ func testInvalidDate( ) throws {
552
+ let conn = try PostgreSQLConnection . makeTest ( transport: . cleartext)
553
+ _ = try conn. simpleQuery ( . createTable( . init(
554
+ name: " timetest " ,
555
+ columns: [ . column( " date " , . date) ]
556
+ ) ) ) . wait ( )
557
+ defer { _ = try ? conn. simpleQuery ( . drop( table: " timetest " ) ) . wait ( ) }
558
+
559
+ struct Time : PostgreSQLTable , Equatable {
560
+ static let postgreSQLTable = " timetest "
561
+ var date : Date
562
+ }
563
+
564
+ _ = try conn. simpleQuery ( . raw( query: " INSERT INTO timetest (date) VALUES ('0214-02-05') " , binds: [ ] ) ) . wait ( )
565
+ let fetch : [ Time ] = try conn. select ( ) . all ( ) . from ( Time . self) . run ( decoding: Time . self) . wait ( )
566
+ switch fetch. count {
567
+ case 1 : XCTAssertEqual ( fetch [ 0 ] . date. timeIntervalSince1970, - 55410998400 )
568
+ default : XCTFail ( " invalid row count " )
569
+ }
570
+ }
549
571
550
572
static var allTests = [
551
573
( " testVersion " , testVersion) ,
@@ -566,6 +588,7 @@ class PostgreSQLConnectionTests: XCTestCase {
566
588
( " testListen " , testListen) ,
567
589
( " testSum " , testSum) ,
568
590
( " testOrderBy " , testOrderBy) ,
591
+ ( " testInvalidDate " , testInvalidDate) ,
569
592
]
570
593
}
571
594
0 commit comments