Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id C2138634005 for ; Sat, 2 May 2009 20:53:21 -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 21609-10 for ; Sat, 2 May 2009 20:53:17 -0300 (ADT) X-Greylist: delayed 00:17:13.943618 by SQLgrey-1.7.6 Received: from tremor.opencloud.co.nz (tremor.opencloud.co.nz [131.203.101.230]) by mail.postgresql.org (Postfix) with ESMTP id 97A67633FFF for ; Sat, 2 May 2009 20:53:17 -0300 (ADT) Received: from 219-89-243-186.adsl.xtra.co.nz ([219.89.243.186] helo=[192.168.1.3]) by tremor.opencloud.co.nz with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1M0OkO-0005on-Bu; Sun, 03 May 2009 11:35:56 +1200 Message-ID: <49FCD8DB.7000707@opencloud.com> Date: Sun, 03 May 2009 11:35:55 +1200 From: Oliver Jowett User-Agent: Thunderbird 2.0.0.21 (X11/20090318) MIME-Version: 1.0 To: John Lister CC: pgsql-jdbc@postgresql.org Subject: Re: getTiIme/Timestamp with TimeZone inconsistency References: <49FC495F.1020302@kickstone.com> In-Reply-To: <49FC495F.1020302@kickstone.com> X-Enigmail-Version: 0.95.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200905/10 X-Sequence-Number: 19560 John Lister wrote: > However in TimestampUtils.getTime, this is initially done, but then > reversed further down and the supplied timezone is used as follows: > > if (ts.hasDate) { > // Rotate it into the requested timezone before we zero out > the date > ..... > cal.setTime(new Date(useCal.getTime().getTime())); > useCal = cal; > } > > is there a reason for this as it seems inconsistent with getTimestamp > and the api docs? I believe this is necessary so that the Time type's invariants (that day/month/year is Jan 1 1970 in the specified timezone) are satisfied. The driver extends the interpretation of getTime(int,Calender) to mean that the returned Time object will be valid for the specified Calendar, regardless of whether a timezone was present in the underlying DB or not. The underlying timezone, if present, is still used when constructing a milliseconds value, but the driver then rotates that resulting value into the target timezone. If we don't do that then you get the strange result that retrieving a time "01:35:42" while providing a Calendar will result in a Time object that does not display as 01:35:42 if you format it with that same Calendar. (I hesitate to say whether this is right or wrong, because as usual JDBC is woefully underspecified in this area, but it's certainly confusing at a minimum) -O