stephencelis / SQLite.swift

A type-safe, Swift-language layer over SQLite3.
MIT License
9.57k stars 1.54k forks source link

Date is not correctly saved #1214

Open LittleLydia opened 1 year ago

LittleLydia commented 1 year ago

Issues are used to track bugs and feature requests. Need help or have a general question? Ask on Stack Overflow (tag sqlite.swift).

Build Information

SQLite.swift version = 0.92 Xcode version = 14.1 macOS version = 13.2.1

General guidelines

I use touch to create a new file ,zero bytes , like touch abcd. then I read the modificationDate by using let modifyDate = try FileManager.default.attributesOfItem(atPath: wholePath)[.modificationDate] as? Date its description like this `▿ 2023-06-07 02:14:52 +0000

but after I fetch it from the db.sqlite, it turns out to be: ▿ 2023-06-07 02:14:52 +0000

Other files which is larger than zero bytes are fine. Just this one. I am really sure before I save it in the db, it is 707796892.7651631

Don't know why

geoffmacd commented 7 months ago

Precision is lost from the date formatter that is used internally to store the date.

If you need perfect precision you need to store dates as a double. Otherwise you cannot guarantee equality.

LittleLydia commented 6 months ago

Precision is lost from the date formatter that is used internally to store the date.

If you need perfect precision you need to store dates as a double. Otherwise you cannot guarantee equality.

OK. I got it. I solved this by saving timestamp. Thanks for the reason.