zzzprojects / Bulk-Operations

C# SQL Bulk Operations | High-performance C# bulk insert, update, delete and merge for SQL Server, SQL Azure, SQL Compact, MySQL, and SQLite.
https://bulk-operations.net
142 stars 36 forks source link

Timestamp already in UTC but being treated as if in local time #23

Closed gingermike closed 5 years ago

gingermike commented 6 years ago

HI,

I'm trying to bulk upsert some data to a Postgres DB using BulkOperations with npgsql. My entities are being mapped to a DataTable before being calling either BulkInsert or BulkMerge depending on the status of the entity in the DB.

Inside my entity, I have a couple of DateTimeOffset's, which I can see have the correct time component @ UTC in the debugger. These fields are mapped to columns in the database with the type timestamptz.

According to the npgsql documentation DateTimeOffsets are converted to UTC (so no change) and put in the DB.

However, when I call BulkMerge or BulkInsert, the timestamps in the DB are 1 hour behind compared to the values I saw in the debugger. It looks like BulkOperations assumes my DateTimeOffset's are in local time (BST) and then either itself or npgsql is performing an unnecessary conversion to UTC.

I feel like I'm going a bit mad, as I'm pretty sure this was working OK a couple of releases OK, but now it seems broken. Any ideas?

JonathanMagnan commented 6 years ago

Hello @gingermike ,

Thank you for reporting. I'm sorry that you get such issue.

Yes, I remember a release a few weeks ago we made about date & PostgreSQL. If I remember well, the BinaryImport have some issue when importing timestamp. We tried to fix it, but looking at your comment, we failed.

We will add more unit tests around DateTime and DateTimeOffset to make sure everything work as expected and fix code that's currently not working. So far, PostgreSQL is the only provider that cause us some issue with DateTime.

Best Regards,

Jonathan

JonathanMagnan commented 6 years ago

Could you tell me which version of the provider you are using to make sure we make some test with this version as well?

gingermike commented 6 years ago

Z.BulkOperations @ 2.13.20 Npgsql @ 3.2.7