Why is a LocalDateTime value on the DST transition of the JVM's timezone shifted by one hour when it is passed to PostgreSQL by the current jdbc driver (42.5.4)? I understood from the docs that LocalDateTime should be passed through as if it were wall clock time.
I did this:
- Create a demo project from spring initializr with jdbc and postgres
- Execute the following against a local database (
template
is an instance ofJdbcTemplate
):
LocalDateTime ts = LocalDateTime.of(2023,3,12,2,0); //DST boundary in Eastern Time Zone
List<LocalDateTime> result = template.query(
"select * from (values(?::timestamp)) as v(ts)",
(rs, rowNum) -> rs.getObject("ts", LocalDateTime.class), ts);
System.out.println("before, after: " + ts + ", " + result.get(0));
//results: before, after: 2023-03-12T02:00, 2023-03-12T03:00
- Change my system's time zone to Hawaii time (no DST there)
- Rerun the same code, and get:
//results: before, after: 2023-03-12T02:00, 2023-03-12T02:00
- Repeat the experiment except use
ts.toString()
as the parameter type - Observe that (before, after) in this case is (2:00, 2:00), independent of JVM timezone (i.e., a String input works as I expected LocalDateTime should work)
Is this a bug, or is this by design?