Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Sources/SQLiteData/Internal/ISO8601.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ import Foundation
extension Date {
@usableFromInline
var iso8601String: String {
let nextUpDate = Date(timeIntervalSinceReferenceDate: timeIntervalSinceReferenceDate.nextUp)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actual fix for the date issue.

if #available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) {
return formatted(.iso8601.currentTimestamp(includingFractionalSeconds: true))
return
nextUpDate
.formatted(
.iso8601.currentTimestamp(includingFractionalSeconds: true)
)
} else {
return DateFormatter.iso8601(includingFractionalSeconds: true).string(from: self)
return DateFormatter.iso8601(includingFractionalSeconds: true)
.string(from: nextUpDate)
}
}

Expand Down
3 changes: 1 addition & 2 deletions Tests/SQLiteDataTests/CloudKitTests/PreviewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@
}
}

@Test
@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
func delete() async throws {
@Test func delete() async throws {
@FetchAll(RemindersList.all, database: userDatabase.database) var remindersLists

try await userDatabase.userWrite { db in
Expand Down
51 changes: 51 additions & 0 deletions Tests/SQLiteDataTests/DateTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import DependenciesTestSupport
import Foundation
import SQLiteData
import SQLiteDataTestSupport
import Testing

@Suite(.dependency(\.defaultDatabase, try .database()))
struct DateTests {
@Dependency(\.defaultDatabase) var database

@Test func roundtrip() throws {
let date = Date(timeIntervalSinceReferenceDate: 793109282.061)
let insertedRecord = try database.write { db in
try Record.insert { Record.Draft(date: date) }
.returning(\.self)
.fetchOne(db)!
}
let updatedRecord = try database.write { db in
try Record
.update(insertedRecord)
.returning(\.self)
.fetchOne(db)!
}
#expect(insertedRecord.date == date)
#expect(insertedRecord.date == updatedRecord.date)
}
}

@Table
private struct Record: Equatable {
let id: Int
var date: Date
}

extension DatabaseWriter where Self == DatabaseQueue {
fileprivate static func database() throws -> DatabaseQueue {
let database = try DatabaseQueue()
try database.write { db in
try #sql(
"""
CREATE TABLE "records" (
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
"date" TEXT NOT NULL
) STRICT
"""
)
.execute(db)
}
return database
}
}