1

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:

  1. Create a demo project from spring initializr with jdbc and postgres
  2. Execute the following against a local database (template is an instance of JdbcTemplate):
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

  1. Change my system's time zone to Hawaii time (no DST there)
  2. Rerun the same code, and get:
//results: before, after: 2023-03-12T02:00, 2023-03-12T02:00
  1. Repeat the experiment except use ts.toString() as the parameter type
  2. 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?

Chad Showalter
  • 211
  • 1
  • 12

0 Answers0