-
Notifications
You must be signed in to change notification settings - Fork 918
Closed
Milestone
Description
Description
When using a java LocalDateTime set to the DST transition hour in the JVM's timezone as a parameter in a query, the value received by PostgreSQL is shifted by one hour.
Driver Version
42.5.4
Java Version
OpenJDK 64-Bit Server VM Corretto-17.0.6.10.1
OS Version
OS X Ventura 13.2.1 (also observed on Ubuntu 16.04.5 LTS)
PostgreSQL Version
PostgreSQL 13.8
To Reproduce
- Set system time to
America/New_York - Run the following code
public class TestDSTBug {
public static void main(String []args) throws Exception {
String url = "jdbc:postgresql://localhost:5432/test";
Properties props = new Properties();
props.setProperty("user", "test");
props.setProperty("password", "test");
LocalDateTime ts = LocalDateTime.of(2023,3,12,2,0); //DST boundary in Eastern Time Zone
try ( Connection conn = DriverManager.getConnection(url, props) ){
try ( PreparedStatement statement = conn.prepareStatement("select * from (values(?::timestamp)) as v(ts)")) {
statement.setObject(1, ts);
try (ResultSet rs = statement.executeQuery( )){
if (rs.next())
System.out.println("before, after (jdbc): " + ts + ", " + rs.getObject(1, LocalDateTime.class));
}
}
}
}
}Result:
//results: before, after (jdbc): 2023-03-12T02:00, 2023-03-12T03:00Expected behaviour
I expected no shift, that is:
//results: before, after (jdbc): 2023-03-12T02:00, 2023-03-12T02:00Note that the results are different (no shift) if the JVM's timezone is one that does not transition to Daylight Savings Time, e.g., UTC or Hawaii. Also note that the results are not shifted if the parameter type is String, regardless of JVM time zone.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels