Skip to content

Instantly share code, notes, and snippets.

@Ciantic
Created October 12, 2023 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ciantic/2aa0a6eb4a1aaa14e24a08a4a44d943c to your computer and use it in GitHub Desktop.
Save Ciantic/2aa0a6eb4a1aaa14e24a08a4a44d943c to your computer and use it in GitHub Desktop.
nodejs-postgresql-timestamp.js
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