postgres icon indicating copy to clipboard operation
postgres copied to clipboard

The date object is off by one year.

Open fushihara opened this issue 11 months ago • 0 comments

Describe the bug The date between January 1 and midnight GMT is different for one year.

Environment is deno v2.1.4, windows 10, postgresql 16. My time zone is Asia/Tokyo ( GMT+9). I passed the string 2025-01-01 04:00:00+09:00 to sql, but Thu Jan 01 2026 04:00:00 GMT+0900 comes back. The moment January 1 is reached by GMT, it will be resolved after 9:00 AM on January 1 in Asia/Tokyo.

import { Client } from "https://deno.land/x/[email protected]/mod.ts";
const client = new Client("postgresql://localhost:5432/postgres");
await client.connect();
await client.queryObject("SET TIME ZONE 'Asia/Tokyo';") // UTC+9
await query(client, `2025-01-01 04:00:00+09:00`);
await query(client, `2025-01-01 05:00:00+09:00`);
await query(client, `2025-01-01 06:00:00+09:00`);
await query(client, `2025-01-01 07:00:00+09:00`);
await query(client, `2025-01-01 08:00:00+09:00`);
await query(client, `2025-01-01 09:00:00+09:00`);
await query(client, `2025-01-01 10:00:00+09:00`);
await query(client, `2025-01-01 11:00:00+09:00`);
async function query(client: Client, timeStr: string) {
  await client.queryObject<{ timestamp_value: Date }>(`SELECT '${timeStr}'::timestamptz AS timestamp_value;`).then(r => {
    console.log(`${timeStr} -> ${r.rows[0].timestamp_value}`)
  });
}

output

Visit chrome://inspect to connect to the debugger.
Deno is waiting for debugger to connect.
Debugger session started.
2025-01-01 04:00:00+09:00 -> Thu Jan 01 2026 04:00:00 GMT+0900 (日本標準時) // I am inputting the year 2025, but the output is 2026
2025-01-01 05:00:00+09:00 -> Thu Jan 01 2026 05:00:00 GMT+0900 (日本標準時)
2025-01-01 06:00:00+09:00 -> Thu Jan 01 2026 06:00:00 GMT+0900 (日本標準時)
2025-01-01 07:00:00+09:00 -> Thu Jan 01 2026 07:00:00 GMT+0900 (日本標準時)
2025-01-01 08:00:00+09:00 -> Thu Jan 01 2026 08:00:00 GMT+0900 (日本標準時)
2025-01-01 09:00:00+09:00 -> Wed Jan 01 2025 09:00:00 GMT+0900 (日本標準時)
2025-01-01 10:00:00+09:00 -> Wed Jan 01 2025 10:00:00 GMT+0900 (日本標準時)
2025-01-01 11:00:00+09:00 -> Wed Jan 01 2025 11:00:00 GMT+0900 (日本標準時)
Program finished. Waiting for inspector to disconnect to exit the process...
Debugger session ended

To Reproduce As per the above code

Expected behavior To return the correct year in any time zone.

Screenshots image

Additional context

If applicable, add any other context about the problem here.

  • deno v2.1.4
  • windows10 64bit
  • postgresql 16 ( The installation is windows. wsl is not used. )

fushihara avatar Dec 31 '24 20:12 fushihara