vapor / fluent

Vapor ORM (queries, models, and relations) for NoSQL and SQL databases
https://docs.vapor.codes/4.0/fluent/overview/
MIT License
1.32k stars 172 forks source link

Fluent 2.5.1 updatedAt to JSON loses precision #441

Closed hyouuu closed 4 years ago

hyouuu commented 6 years ago

For example, a model has updatedAt = 2018-04-06 17:18:32.185242+00 in postgres, and a route returns model.makeJSON(), then in the json content the updatedAt field has 2018-04-06T17:18:32.185Z, which lost the last 3 digits 242 thus lost the precision.

As a result, if I pass the updatedAt back from client to server to .filter("updatedAt", .greaterThan, passedBackDate), the result would still contain that entry since it's .185242 is greater than 185.

I think there is no reason to omit 3 digits and we should just keep what is stored in database intact when converting to json.

hyouuu commented 1 year ago

@0xTim any context on why this was closed? Was it resolved? cc @tanner0101

0xTim commented 1 year ago

I'm guessing Swift's Date only supports millisecond precision so that's why

hyouuu commented 1 year ago

I'm guessing Swift's Date only supports millisecond precision so that's why

Interesting - did some search and this shows that the millisecond precision might only happen with DateFormatter & timeIntervalSince1970, and using timeIntervalSinceReferenceDate it would work properly - any way we can improve here? https://stackoverflow.com/questions/64594108/swift-precision-with-timeintervalsince1970