Created
October 12, 2023 10:28
-
-
Save Ciantic/2aa0a6eb4a1aaa14e24a08a4a44d943c to your computer and use it in GitHub Desktop.
nodejs-postgresql-timestamp.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const pool = new Pool({ | |
max: 300, | |
connectionTimeoutMillis: 20000, | |
host: "127.0.0.1", | |
port: 5432, | |
user: 'citus', | |
password: () => "password", | |
database: 'citus', | |
ssl: false, | |
}); | |
describe('test', () => { | |
test('timestamppe', async () => { | |
const now = new Date(); | |
const res = await pool.query("SELECT to_timestamp($1) as ts", [now.getTime() / 1000]); | |
// THIS SUCCEEDS | |
expect(res.rows[0].ts.getTime()).toBe(now.getTime()); | |
}); | |
test('timestamppe 2', async () => { | |
const now = new Date(); | |
await pool.query("CREATE TEMPORARY TABLE test (ts timestamp);"); | |
const res = await pool.query( | |
"INSERT INTO test (ts) VALUES (to_timestamp($1)) RETURNING *;", | |
[now.getTime() / 1000] | |
); | |
// THIS FAILS! WHY? It gives 3 hour difference just for my timezone | |
expect(res.rows[0].ts.getTime()).toBe(now.getTime()); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment