Skip to content
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

The date object is off by one year. #494

Open
fushihara opened this issue Dec 31, 2024 · 0 comments
Open

The date object is off by one year. #494

fushihara opened this issue Dec 31, 2024 · 0 comments

Comments

@fushihara
Copy link

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. )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant