Skip to content

LocalDateTime conversion to timestamp without time zone is affected by JVM timezone at DST boundary #2850

@chadshowalter

Description

@chadshowalter

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

  1. Set system time to America/New_York
  2. 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:00

Expected behaviour
I expected no shift, that is:

//results: before, after (jdbc): 2023-03-12T02:00, 2023-03-12T02:00

Note 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions