DateTime timestamp type doesn't discard the timezone info.
See original GitHub issueBug description
Hi!
I am using Prisma with Postgresql and am encountering some weird issues with timestamps and timezones that feel like a bug.
For testing, I created the following columns:
testAt DateTime
testTzAt DateTime @db.Timestamptz
The Prisma DateTime
type maps to the native Postgresql type @db.Timestamp (timestamp without timezone). This should discard the timezone info and not convert it to UTC. But, Prisma appears to automatically convert the timestamp to UTC before writing it to the db.
Creating the row with below values:
testAt: '2021-06-24T01:00.000+02:00',
testTzAt: '2021-06-24T01:00.000+02:00',
When I read the selected row, this is what I get back:
testAt: 2021-06-23T23:00:00.000Z, (incorrect, expected it to be `2021-06-24T01:00.000`)
testTzAt: 2021-06-23T23:00:00.000Z, (correct)
If I use a raw SQL query with the same values instead, it works as expected:
testAt: 2021-06-24T01:00:00.000Z,
testTzAt: 2021-06-23T23:00:00.000Z,
Right now I do not see any differences between @db.Timestamp and @db.Timestamptz when using Prisma with Postgresql - this seems clearly incorrect.
Also, it feels like Prisma should be using Timestamptz as the native default type mapping for DateTime, if it’s converting timestamps to UTC under the hood anyway. What is the reason that it is not?
Expected behavior
When saving 2021-06-24T01:00.000+02:00
in a normal Timestamp field the expected saved value should be 2021-06-24T01:00:00.000Z
Environment & setup
- OS: Ubuntu
- Database: Postgres
- Node.js version: 14.15.4
Prisma Version
prisma : 2.25.0
@prisma/client : 2.25.0
Current platform : debian-openssl-1.1.x
Query Engine : query-engine c838e79f39885bc8e1611849b1eb28b5bb5bc922 (at node_modules/@prisma/engines/query-engine-debian-openssl-1.1.x)
Migration Engine : migration-engine-cli c838e79f39885bc8e1611849b1eb28b5bb5bc922 (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine : introspection-core c838e79f39885bc8e1611849b1eb28b5bb5bc922 (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary : prisma-fmt c838e79f39885bc8e1611849b1eb28b5bb5bc922 (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash : c838e79f39885bc8e1611849b1eb28b5bb5bc922
Studio : 0.402.0
Preview Features : filterJson
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5 (3 by maintainers)
Top GitHub Comments
Ok @kladnik, does look I closed this prematurely.
I can reproduce the behavior and I also agree it is not correct. Marking this as confirmed bug.
Any progress on this? This seems like a crucial bug and is making things annoyingly hard whenever we are handling
DateTime
fields.