@@ -26,6 +26,31 @@ final class SQLiteNIOTests: XCTestCase {
26
26
let rows = try conn. query ( " SELECT ? as date " , [ date. sqliteData!] ) . wait ( )
27
27
XCTAssertEqual ( rows [ 0 ] . column ( " date " ) , . float( date. timeIntervalSince1970) )
28
28
XCTAssertEqual ( Date ( sqliteData: rows [ 0 ] . column ( " date " ) !) ? . description, date. description)
29
+ XCTAssertEqual ( Date ( sqliteData: rows [ 0 ] . column ( " date " ) !) , date)
30
+ XCTAssertEqual ( Date ( sqliteData: rows [ 0 ] . column ( " date " ) !) ? . timeIntervalSinceReferenceDate, date. timeIntervalSinceReferenceDate)
31
+ }
32
+
33
+ func testTimestampStorageRoundToMicroseconds( ) throws {
34
+ let conn = try SQLiteConnection . open ( storage: . memory, threadPool: self . threadPool, on: self . eventLoop) . wait ( )
35
+ defer { try ! conn. close ( ) . wait ( ) }
36
+
37
+ // Test value that when read back out of sqlite results in 7 decimal places that we need to round to microseconds
38
+ let date = Date ( timeIntervalSinceReferenceDate: 689658914.293192 )
39
+ let rows = try conn. query ( " SELECT ? as date " , [ date. sqliteData!] ) . wait ( )
40
+ XCTAssertEqual ( rows [ 0 ] . column ( " date " ) , . float( date. timeIntervalSince1970) )
41
+ XCTAssertEqual ( Date ( sqliteData: rows [ 0 ] . column ( " date " ) !) ? . description, date. description)
42
+ XCTAssertEqual ( Date ( sqliteData: rows [ 0 ] . column ( " date " ) !) , date)
43
+ XCTAssertEqual ( Date ( sqliteData: rows [ 0 ] . column ( " date " ) !) ? . timeIntervalSinceReferenceDate, date. timeIntervalSinceReferenceDate)
44
+ }
45
+
46
+ func testDateRoundToMicroseconds( ) throws {
47
+ let secondsSinceUnixEpoch = 1667950774.6214828
48
+ let secondsSinceSwiftReference = 689643574.621483
49
+ let timestamp = SQLiteData . float ( secondsSinceUnixEpoch)
50
+ let date = try XCTUnwrap ( Date ( sqliteData: timestamp) )
51
+ XCTAssertEqual ( date. timeIntervalSince1970, secondsSinceUnixEpoch)
52
+ XCTAssertEqual ( date. timeIntervalSinceReferenceDate, secondsSinceSwiftReference)
53
+ XCTAssertEqual ( date. sqliteData, . float( secondsSinceUnixEpoch) )
29
54
}
30
55
31
56
func testTimestampStorageInDateColumnIntegralValue( ) throws {
0 commit comments