Date equality mismatch due to millisecond rounding differences between SQLite and CloudKit #275
Replies: 1 comment 1 reply
-
|
Hi @lukaskubanek, this seems more like a data modeling issue for the user of the library rather than an issue with the library itself. If the user needs precision, then they should know not to use doubles. They should probably use integers. And they can either store this integer directly in their model, or they can cook up a custom We even had to deal with this just before releasing the library, where we had to switch from double timestamps to integers. Since this isn't an issue with the library I am going to convert it to a discussion. Please feel free to continue the conversation over there! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
When synchronizing
Datefields between the local SQLite database (with the default serialization strategy) and CloudKit,Datevalues that should be identical are often detected as changed inCKRecord.update(with:row:columnNames:parentForeignKey:).I observed this with
Reminder.dueDatein the Reminders example app:Although both SQLite and CloudKit appear to serialize
Datevalues with millisecond precision, the repeated conversion introduces rounding errors. As a result, the equality check ofDatevia bit-exact comparison fails, and the value is mistakenly treated as modified.Not sure whether the correct solution is to normalize all persisted dates or to compare with a tolerance, but in any case, we should prevent reporting false positives to avoid divergence between the local SQLite and CloudKit databases.
Checklist
mainbranch of this package.Expected behavior
No response
Actual behavior
No response
Reproducing project
No response
SQLiteData version information
main
Sharing version information
No response
GRDB version information
No response
Destination operating system
iOS 18 / macOS 15
Xcode version information
26.1 β3
Swift Compiler version information
Beta Was this translation helpful? Give feedback.
All reactions