Received: from localhost (uranus.hub.org [200.46.204.60]) by postgresql.org (Postfix) with ESMTP id DFCEA9FA491 for ; Fri, 10 Nov 2006 18:10:25 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.60]) (amavisd-new, port 10024) with ESMTP id 57956-08 for ; Fri, 10 Nov 2006 18:10:24 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [131.203.101.226]) by postgresql.org (Postfix) with ESMTP id AAFDD9F9F79 for ; Fri, 10 Nov 2006 18:10:23 -0400 (AST) Received: from 219-89-241-92.adsl.xtra.co.nz ([219.89.241.92] helo=[10.1.1.3]) by yass.opencloud.co.nz with asmtp (TLS-1.0:DHE_RSA_AES_128_CBC_SHA:16) (Exim 4.34) id 1GieZi-0003rh-8o; Sat, 11 Nov 2006 11:10:14 +1300 Message-ID: <4554F8AE.6000202@opencloud.com> Date: Fri, 10 Nov 2006 22:09:50 +0000 From: Oliver Jowett User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Richard Cook CC: imad , pgsql-jdbc@postgresql.org Subject: Re: Bug in TimestampUtils.java? References: <20061110161940.19582.qmail@web60222.mail.yahoo.com> In-Reply-To: <20061110161940.19582.qmail@web60222.mail.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/56 X-Sequence-Number: 16098 Richard Cook wrote: > Oliver, > > Below is the debug output from TimestampUtils.java > > It parses the date string that says -05 into an -0400 Date object. > > Rich > > > Date String: 2006-10-29 23:00:00-05 > > debug output ---> Parsed date '2006-10-29 23:00:00-05' in zone > America/New_York as 2006-10-29 AD 00:00:00 -0400 (millis=1162094400000) I see no bug here. (1) Date does not store a timezone offset, so timezone info cannot be returned in the Date. (2) getDate() returns a java.sql.Date which by definition must have no hour/minute/second component (see javadoc) (3) The driver uses the provided Calendar (or the local JVM timezone if no Calendar was provided) to generate the Date it will return, in this case America/New_York (-0400) (4) The driver discards the hour/minute/second part of the value returned by the server, and sets the year/month/day on the returned Date using the Calendar from (3) So what you end up with is a java.sql.Date for "2006-10-29 00:00:00" in the -0400 timezone, which is exactly correct in terms of the semantics of getDate, but isn't actually the same instant as the server returned. As you have probably worked out by now, using getDate() on a full timestamp type is a bit confusing because of the H/M/S truncation thing, especially when timezones are involved. It's arguable whether the driver should first convert to the timezone of the provided Calendar before discarding the hour/minute/second component or not .. JDBC doesn't say anything about how TIMESTAMP to DATE conversion should be done. If you want to retrieve an instant in time complete with hour/minute/second info, you should be using getTimestamp() not getDate(). Also note that "timestamp with time zone" does not actually *store* a timezone, see the docs for details. JDBC doesn't give you any way I can see to get at the timezone info returned by the server anyway. -O