question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DateTime timestamp type doesn't discard the timezone info.

See original GitHub issue

Bug 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:open
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
pantharshit00commented, Oct 14, 2021

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.

1reaction
kladnikcommented, Feb 21, 2022

Any progress on this? This seems like a crucial bug and is making things annoyingly hard whenever we are handling DateTime fields.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I remove a pytz timezone from a datetime object?
The solution is to convert your datetime.datetime object to UTC (so everything in your database is UTC since it can't specify timezone) then ......
Read more >
How to remove timezone information from DateTime object in ...
To remove timestamp, tzinfo has to be set None when calling replace() function. First, create a DateTime object with current time using datetime ......
Read more >
datetime — Basic date and time types — Python 3.11.1 ...
Date and time objects may be categorized as “aware” or “naive” depending on whether or not they include timezone information.
Read more >
Date/Time Types | Pivotal Greenplum Docs
If no time zone is stated in the input string, then it is assumed to be in the time zone indicated by the...
Read more >
TO_TIMESTAMP function - Amazon Redshift
Formats that include a time zone ( TZ , tz , or OF ) are not supported as input. For valid timestamp formats,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found