Message-ID: From: "Frank-Gu-81 (@Frank-Gu-81)" To: "pgjdbc/pgjdbc" Date: Thu, 21 Aug 2025 22:06:38 +0000 Subject: Re: [pgjdbc/pgjdbc] issue #3692: Wrong time formatting ResultSet.getTime(); for Europe/Belgrade and "Europe/Prague" In-Reply-To: References: List-Id: X-GitHub-Author-Login: Frank-Gu-81 X-GitHub-Comment-Id: 3212211588 X-GitHub-Comment-Type: issue_comment X-GitHub-Issue: 3692 X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-Type: comment X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/issues/3692#issuecomment-3212211588 Content-Type: text/plain; charset=utf-8 Thanks for the discussion — following up with another observation that might help narrow this down. ## Context I’m also seeing a possible time-of-day mismatch around DST when calling `ResultSet#getTime(int)` without a Calendar on `TIMESTAMP` / `TIMESTAMPTZ`. ## Environment * PgJDBC: 42.7.7 * Java: 21 * PostgreSQL server: 16.4 * OS: macOS 15.6 * JVM default timezone at runtime: America/Los_Angeles ## Steps to reproduce 1. Set the JVM default zone to America/Los_Angeles (any DST-observing zone should work): ```java TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); 2. Create a table and insert two rows (one in standard time, one in DST): ```sql CREATE TEMP TABLE test_timestamps ( ts_without_tz timestamp, ts_with_tz timestamptz ); INSERT INTO test_timestamps VALUES ('2023-11-10 09:00:00', '2023-11-10 09:00:00-08'), -- PST (UTC-8) ('2023-03-13 09:00:00', '2023-03-13 09:00:00-07'); -- PDT (UTC-7) ``` 3. Query and call `rs.getTime(col)` (no Calendar) on each column. ```java try (var c = DriverManager.getConnection(PG_URL); var s = c.createStatement(); var rs = s.executeQuery("select ts_without_tz, ts_with_tz from test_timestamps order by 1")) { while (rs.next()) { var tNoCal_noTz = rs.getTime(1); // no Calendar var tNoCal_tz = rs.getTime(2); // no Calendar var ts = rs.getTimestamp(2); // compare against local wall-clock at the instant var lt = ts.toInstant().atZone(ZoneId.systemDefault()).toLocalTime(); System.out.printf("noCal timestamp=%s getTime=%s localTimeAtInstant=%s%n", ts, tNoCal_tz, lt); } } ``` ## Observed vs expected (America/Los_Angeles) * 2023-11-10 09:00 → `getTime(...)` returns 09:00:00 (as expected). * 2023-03-13 09:00 → `getTime(...)` returns 08:00:00, while: ```java var lt = ts.toInstant().atZone(ZoneId.systemDefault()).toLocalTime(); // → 09:00 ``` shows 09:00 at that instant in the JVM zone. ## Possible cause This seems consistent with the 1970-01-01 “epoch rebasing” noted earlier, and I think it's coming from the `PgResultSet#getTime(..)` path ending up in `TimestampUtils.convertToTime(...)`. Per its docs, `convertToTime()` normalizes the value so the date part becomes 1970-01-01 in the selected timezone.