prisma / tiberius

TDS 7.2+ (Microsoft SQL Server) driver for Rust
Apache License 2.0
327 stars 119 forks source link

Correctly convert DateTimeOffset to/from database #269

Closed pimeys closed 1 year ago

pimeys commented 1 year ago

Rebased version of https://github.com/prisma/tiberius/pull/261

Problem

As described in the referenced issue, the way tiberius converts between DateTime<FixedOffset> and DateTimeOffset is incorrect. Currently, tiberius uses the DateTime<FixedOffset>'s local datetime + offset to create the DateTimeOffset. This means that what is stored in the database will be a local datetime and its offset.

However, as described in the docs:

"The data is stored in the database and processed, compared, sorted, and indexed in the server as in UTC. The time zone offset will be preserved in the database for retrieval."

the value should be stored in the database as a UTC datetime + offset.

The consequence of tiberius's current behavior is that retrieving DateTimeOffset values, that have been inserted by tiberius, using any other methods or languages will yield the wrong value. Likewise, using tiberius to retrieve values that have been inserted by other methods or languages will also yield the wrong value.

Changes

Closes https://github.com/prisma/tiberius/issues/260