New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timestamp type parser breaks if timezone is not GMT #239
Comments
So apparently the database has the correct UTC timestamp stored and the difference comes from library conversion logic. By default const timestampParser = { name: 'timestamp', parse: value => Date.parse(`${value} UTC`) }; // or `${value}Z`
const clientConfiguration = { typeParsers: [timestampParser] };
const pool = createPool(connectionUri, clientConfiguration); or even better const timestampParser = { name: 'timestamp', parse: value => new Date(`${value} UTC`) };
const clientConfiguration = { typeParsers: [timestampParser] };
const pool = createPool(connectionUri, clientConfiguration); |
🎉 This issue has been resolved in version 24.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
@gajus here 1e9a484#diff-967766d7babb268d6e22ea686e9fe005f2bd15b2235d762cc61db0479590a278R6 > select TIMESTAMP '2004-10-19 10:23:54';
timestamp
---------------------
2004-10-19 10:23:54
(1 row)
> select TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54';
timestamptz
------------------------
2004-10-19 10:23:54+04
(1 row) i.e. result expession will be > Date.parse('2004-10-19 10:23:54+04')
1098167034000
> Date.parse('2004-10-19 10:23:54+04 UTC')
1098181434000 |
I'm from São Paulo, so my default timezone is UTC-3. Whenever I try to use the
timestamp
field, its values are returned ahead of time (exactly the time difference between my local time and GMT).Expected Behavior
The timestamp returned from a
select
query should be the time stored inside the database.Current Behavior
The timestamp returned from a
select
query is ahead of the true value stored in the database by exactly the difference from my local time to GMT.Possible Solution
Timezone conversion error, can't pinpoint because I couldn't understand the library source code. However,
timestamptz
works flawlessly. So a possible solution is to check whytimestamptz
behavior is different fromtimestamp
when the GMT timezone is used.Steps to Reproduce
1 - Be in a system with a different timezone from GMT
2 -
Logs
My local time: 2020-12-04 19:26:00
UTC time: 2020-12-04 22:26:00
The text was updated successfully, but these errors were encountered: