X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 162038B9EEE for ; Mon, 14 Feb 2005 15:50:49 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 18884-04 for ; Mon, 14 Feb 2005 15:50:45 +0000 (GMT) Received: from morpheus.sme.de (morpheus.sme.de [82.135.32.123]) by svr1.postgresql.org (Postfix) with ESMTP id E73CE8B9B30 for ; Mon, 14 Feb 2005 15:50:41 +0000 (GMT) Received: from morpheus.sme.de (localhost [127.0.0.1]) by morpheus.sme.de (Postfix) with SMTP id 0570A417BF for ; Mon, 14 Feb 2005 16:49:10 +0100 (CET) Received: from morpheus.sme.de (localhost [127.0.0.1]) by morpheus.sme.de (Postfix) with ESMTP id C89D7E8F4 for ; Mon, 14 Feb 2005 16:49:09 +0100 (CET) Received: from 193.128.157.68 (SquirrelMail authenticated user malsy) by morpheus.sme.de with HTTP; Mon, 14 Feb 2005 16:49:09 +0100 (CET) Message-ID: <22997.193.128.157.68.1108396149.squirrel@morpheus.sme.de> Date: Mon, 14 Feb 2005 16:49:09 +0100 (CET) Subject: Daylight Safing Problem 2004-10-31 00:00:00 (UTC) From: matthias.malsy@sme.de To: pgsql-jdbc@postgresql.org User-Agent: SquirrelMail/1.4.2 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 X-Priority: 3 Importance: Normal Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.178 tagged_above=0 required=5 tests=NO_REAL_NAME X-Spam-Level: X-Archive-Number: 200502/102 X-Sequence-Number: 12282 Dear pgjdbc users and developers, hope you can help me fixing my daylight safing problem. Thx in advance Matthias Description: ------------ I reduced my problem to a simple testcase just storing and loading a date from the database. The tescase fails for the time interval of 2004-10-31 00:00:00 to 01:00:00 (UTC). In order to stay ANSI conform, I use the 'timestamp [without timezone]' data type. - create table mdso_demo (id int, d timestamp) Scenario: --------- I am storing sales data (containing sales date/time) in a database by ignoring the timezone in order to make it comparable across multiple timezones. The sales date is deliverd by a foreign system as a String and is parsed by an UTC-SimpleDateFormatter. After safing and loading, the date (and its milliseconds) differs by 1 hour. Output (running on CET/CEST): ----------------------------- -- Date parsed and stored (running on CET/CEST) ----------- Sun Oct 31 02:00:00 CEST 2004 1099180800000 31 Oct 2004 00:00:00 GMT -- Date loaded from database Sun Oct 31 02:00:00 CET 2004 1099184400000 31 Oct 2004 01:00:00 GMT Environment: ------------ PG: PostgreSQL 7.4.6 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.3.4 (pre 3.3.5 20040809) JDBC: pg74.215.jdbc3.jar JAVA: java version "1.4.2_06" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_06-b0= 3) Java HotSpot(TM) Client VM (build 1.4.2_06-b03, mixed mode) Database _and_ Client are running at CET/CEST. The Code: --------- public void testDaylightSavings3() throws Exception { String database =3D "bkgrsta_dev"; String username =3D"mat"; String password =3D ""; SimpleDateFormat sdf =3D new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")= ; TimeZone tzGMT =3D TimeZone.getTimeZone("etc/UTC"); sdf.setTimeZone( tzGMT ); Date testDate =3D sdf.parse("2004-10-31 00:00:00"); System.out.println("---------------- A Date -----------"); System.out.println(testDate); System.out.println(testDate.getTime()); System.out.println(testDate.toGMTString()); Class.forName("org.postgresql.Driver"); //load the driver Connection db =3D DriverManager.getConnection("jdbc:postgresql:"+database, username, password); //connect to the db Statement sql =3D db.createStatement(); //create a statement that= we can use later String sqlText =3D "create table mdso_demo (id int, d timestamp)"= ; sql.executeUpdate(sqlText); Timestamp ts =3D new Timestamp(testDate.getTime()); System.out.println("---------------- Converted to a Timestamp ----------------"); System.out.println(ts); System.out.println(ts.getTime()); System.out.println(ts.toGMTString()); sqlText =3D "insert into mdso_demo values (?,?)"; PreparedStatement ps =3D db.prepareStatement(sqlText); ps.setInt(1,1); ps.setTimestamp(2,ts); ps.execute(); System.out.println("----------------- Date has been inserted into the database ----------"); Statement st =3D db.createStatement(); ResultSet rs =3D st.executeQuery("select id, d from mdso_demo"); boolean b =3D rs.next(); Timestamp resTime =3D rs.getTimestamp(2); System.out.println("--------------- Timestamp loaded from databas= e -----------"); System.out.println(resTime); System.out.println(resTime.getTime()); System.out.println(resTime.toGMTString()); Date resDate =3D new Date(resTime.getTime()); System.out.println("--------------- Converted to a date -----------------"); System.out.println(resDate); System.out.println(resDate.getTime()); System.out.println(resDate.toGMTString()); long diff =3D resDate.getTime() - testDate.getTime(); System.out.println("----------- difference was ------------------------- "); System.out.println("ms: "+ diff + " h:" + diff /(1000*60*60))= ; rs.close(); sqlText =3D"drop table mdso_demo"; sql.execute(sqlText); db.close(); }