protected void setUp() throws Exception { // We must change the default TZ before establishing the connection. TimeZone.setDefault( TimeZone.getTimeZone("GMT+01")); // Arbitrary timezone that doesn't match our test timezones connect(); TestUtil.createTable( con, "testtimezone", "seq int4, tstz timestamp with time zone, ts timestamp without time zone, t time without time zone, tz time with time zone, d date"); // This is not obvious, but the "gmt-3" timezone is actually 3 hours *ahead* of GMT // so will produce +03 timestamptz output con.createStatement().executeUpdate("set timezone = 'gmt-3'"); min73 = TestUtil.haveMinimumServerVersion(con, "7.3"); min74 = TestUtil.haveMinimumServerVersion(con, "7.4"); // System.err.println("++++++ TESTS START (" + getName() + ") ++++++"); }
public void testTimezoneWithSeconds() throws SQLException { if (!TestUtil.haveMinimumServerVersion(con, "8.2")) return; Statement stmt = con.createStatement(); stmt.execute("SET TimeZone = 'Europe/Paris'"); for (int i = 0; i < PREPARE_THRESHOLD; i++) { PreparedStatement ps = con.prepareStatement("SELECT '1920-01-01'::timestamptz"); ResultSet rs = ps.executeQuery(); rs.next(); // select extract(epoch from '1920-01-01'::timestamptz - 'epoch'::timestamptz) * 1000; assertEquals(-1577923200000L, rs.getTimestamp(1).getTime()); ps.close(); } }