pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: John Lister <john.lister-ps@kickstone.com>
To: Oliver Jowett <oliver@opencloud.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: getTiIme/Timestamp with TimeZone inconsistency
Date: Sun, 03 May 2009 11:41:03 +0100
Message-ID: <49FD74BF.7050003@kickstone.com> (raw)
In-Reply-To: <49FCD8DB.7000707@opencloud.com>
References: <49FC495F.1020302@kickstone.com>
	<49FCD8DB.7000707@opencloud.com>


Oliver Jowett wrote:
> 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
>
>   

I agree the JDBC spec is vague, but I read the spec such that the 
supplied calendar is *only* used if the server doesn't support a 
timezone. I think my main concern is that setTimestamp behaves 
differently to setTime. I'm not sure which is correct (i'd tend to the 
former) but i think they should behave the same...

I'm not sure what the correct behaviour should be if the server has a 
timezone and you specify one to use. Hopefully the app writer would only 
use this case for none timezone columns/results.... maybe too much to 
ask for :)

JOHN




view thread (4+ messages)  latest in thread

Message-ID: <49FD74BF.7050003@kickstone.com>
Permalink:  ../49FD74BF.7050003@kickstone.com/
Also on:    postgresql.org/message-id/49FD74BF.7050003@kickstone.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: john.lister-ps@kickstone.com, oliver@opencloud.com
  Subject: Re: getTiIme/Timestamp with TimeZone inconsistency
  In-Reply-To: <49FD74BF.7050003@kickstone.com>
  References: <49FC495F.1020302@kickstone.com> <49FCD8DB.7000707@opencloud.com> <49FD74BF.7050003@kickstone.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox