Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 097DD633AD9 for ; Tue, 5 May 2009 19:40:41 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 26718-05 for ; Tue, 5 May 2009 19:40:36 -0300 (ADT) Received: from mx1.hub.org (mx1.hub.org [200.46.208.106]) by mail.postgresql.org (Postfix) with ESMTP id 36F39633946 for ; Tue, 5 May 2009 19:40:34 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mk-filter-1-a-1.mail.uk.tiscali.com (mk-filter-1-a-1.mail.uk.tiscali.com [212.74.100.52]) by mx1.hub.org (Postfix) with ESMTP id 66FCE125CCF4 for ; Tue, 5 May 2009 16:37:30 -0300 (ADT) X-Trace: 194039675/mk-filter-1.mail.uk.tiscali.com/B2C/$b2c-THROTTLED-DYNAMIC/b2c-CUSTOMER-DYNAMIC-IP/62.64.158.120/None/john.lister@kickstone.com X-SBRS: None X-RemoteIP: 62.64.158.120 X-IP-MAIL-FROM: john.lister@kickstone.com X-SMTP-AUTH: X-MUA: Thunderbird 2.0.0.21 (Windows/20090302) X-IP-BHB: Once X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvcHAP4xAEo+QJ54/2dsb2JhbAAIN8BhCJAOgi4aCIExBQ X-IronPort-AV: E=Sophos;i="4.40,299,1238972400"; d="scan'208";a="194039675" Received: from 62-64-158-120.dynamic.dial.as9105.com (HELO [192.168.6.11]) ([62.64.158.120]) by smtp.tiscali.co.uk with ESMTP; 05 May 2009 20:36:13 +0100 Message-ID: <4A0337A4.7090505@kickstone.com> Date: Thu, 07 May 2009 20:33:56 +0100 From: John Lister User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) MIME-Version: 1.0 To: Kris Jurka CC: pgsql-jdbc@postgresql.org Subject: Re: Unit test patches References: <49FAC740.1060607@kickstone.com> <49FDDA33.5070009@kickstone.com> <28431.1241374645@sss.pgh.pa.us> <49FDEDA2.7040107@kickstone.com> <4A020049.9050702@kickstone.com> <49FF62D4.2010406@ejurka.com> In-Reply-To: <49FF62D4.2010406@ejurka.com> Content-Type: multipart/mixed; boundary="------------070804060809000505020304" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.8 tagged_above=0 required=5 tests=DATE_IN_FUTURE_24_48=2.8 X-Spam-Level: ** X-Archive-Number: 200905/40 X-Sequence-Number: 19590 This is a multi-part message in MIME format. --------------070804060809000505020304 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Kris Jurka wrote: > John Lister wrote: > >> for all of these i do this first: >> Time t=new Time(28862000); // this should be 8:01:02 UTC >> >> Now the odd bit >> Europe/London (DST auto-adjust enabled but not active) - 09:01:02 >> - This is wrong, it should be equiv to GMT > > Yes, but not at the unix epoch. See the section titled "Permanent > summer, 1968–1971" > > http://www.nmm.ac.uk/explore/astronomy-and-time/time-facts/british-summer-time/ > I assumed that something was going on around the epoch, but didn't realise that - amazing what you learn about your own country. Still there is bizarre behaviour with the java time stuff (nothing new there then...) Assuming timezone=Europe/London then TimeZone t=TimeZone.getDefault(); t.inDaylightTime(new Date(28862000L)) == false t.getRawOffset() == 0 t.getOffset(28862000L) == 3600000 It would seem that inDaylightTime doesn't take into account historical stuff... Anyway patch attached that fixes the problem for all (tested) timezones.. Can you let me know how you get on... Also, for the failing test - I'm fairly sure the driver shouldn't be inserting "9:01:02" for the value of "5:1:2+03" when the current timezone is "Europe/London" without DST - as it uses the epoch to calculate the offsets which while historically correct are now incorrect. Note that setting it to simply GMT works as expected. I suspect that the date component should be initialised to the current date instead of 1/1/1970 for internal manipulation within the driver and reset before returning anything to the user as a sql.Time value. Thoughts JOHN --------------070804060809000505020304 Content-Type: text/plain; name="TimeTest.java.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="TimeTest.java.patch" Index: TimeTest.java =================================================================== RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/test/jdbc2/TimeTest.java,v retrieving revision 1.18 diff -u -r1.18 TimeTest.java --- TimeTest.java 8 Jan 2008 06:56:31 -0000 1.18 +++ TimeTest.java 7 May 2009 19:07:16 -0000 @@ -59,9 +59,9 @@ cal.setTimeZone(TimeZone.getTimeZone("GMT")); - long localOffset = Calendar.getInstance().get(Calendar.ZONE_OFFSET); + int localOffset=Calendar.getInstance().getTimeZone().getOffset(midnight.getTime()); - /* set the time to midnight to make this easy */ + // set the time to midnight to make this easy assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testtime", "'00:00:00','00:00:00'"))); assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testtime", "'00:00:00.1','00:00:00.01'"))); assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testtime", "CAST(CAST(now() AS timestamp without time zone) AS time),now()"))); @@ -265,11 +265,7 @@ t = rs.getTime(1); assertNotNull(t); java.sql.Time tmpTime = java.sql.Time.valueOf("5:1:2"); - int localoffset = java.util.Calendar.getInstance().getTimeZone().getRawOffset(); - if (java.util.Calendar.getInstance().getTimeZone().inDaylightTime(tmpTime)) - { - localoffset += 60 * 60 * 1000; - } + int localoffset=java.util.Calendar.getInstance().getTimeZone().getOffset(tmpTime.getTime()); int Timeoffset = 3 * 60 * 60 * 1000; tmpTime.setTime(tmpTime.getTime() + Timeoffset + localoffset); assertEquals(makeTime(tmpTime.getHours(), tmpTime.getMinutes(), tmpTime.getSeconds()), t); @@ -278,11 +274,7 @@ t = rs.getTime(1); assertNotNull(t); tmpTime = java.sql.Time.valueOf("23:59:59"); - localoffset = java.util.Calendar.getInstance().getTimeZone().getRawOffset(); - if (java.util.Calendar.getInstance().getTimeZone().inDaylightTime(tmpTime)) - { - localoffset += 60 * 60 * 1000; - } + localoffset=java.util.Calendar.getInstance().getTimeZone().getOffset(tmpTime.getTime()); Timeoffset = -11 * 60 * 60 * 1000; tmpTime.setTime(tmpTime.getTime() + Timeoffset + localoffset); assertEquals(makeTime(tmpTime.getHours(), tmpTime.getMinutes(), tmpTime.getSeconds()), t); --------------070804060809000505020304--