pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
TimeZone related issues in org.postgresql.jdbc2.TimestampUtils
4+ messages / 3 participants
[nested] [flat]

* TimeZone related issues in org.postgresql.jdbc2.TimestampUtils
@ 2009-09-13 20:31 Carsten Klein <carsten.klein@axn-software.de>
  2009-09-13 23:22 ` Re: TimeZone related issues in org.postgresql.jdbc2.TimestampUtils Oliver Jowett <oliver@opencloud.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Carsten Klein @ 2009-09-13 20:31 UTC (permalink / raw)
  To: pgsql-jdbc


Hi All,

in an application that uses TIMESTAMP WITH TIME ZONE as the type for
certain attributes, we stumbled across the problem that, sometimes, the
values returned from the database will be adjusted so that the time zone
offset will be added/subtracted from the actual time stored in the
database.

Example: "2009-09-11 15:00:00+02" will be returned by TimestampUtils as
"2009-09-11 13:00:00".

This is due to the fact that in TimestampUtils.toTimestamp(...) and
TimestampUtils.toTime(...) the following will be used for returning the
Time or Timestamp instances, respectively:


toTimestamp(): Timestamp result = new Timestamp(useCal.getTime().getTime());

toTime():  Time result = new Time(useCal.getTime().getTime());

This however, leads to the aforementioned, incorrect results, since the
Calendar implementation, on getTime() will now adjust the initially
correct date and time based on the time zone information that is stored
with the data.

Whilst trying to work around that problem, I found out, that it would be
best to use

toTimestamp():
  DateFormat df = DateFormat.getDateTimeInstance();
  df.setTimeZone( useCal.getTimeZone() );
  Timestamp result = new Timestamp( df.parse( df.format( useCal.getTime()
) ).getTime() );

toTime():
  DateFormat df = DateFormat.getTimeInstance();
  df.setTimeZone( useCal.getTimeZone() );
  Time result = new Time( df.parse( df.format( useCal.getTime() )
).getTime() );

This then will lead to the correct results.

TIA for fixing this!

Best Regards

Carsten Klein


--

axn software UG (haftungsbeschränkt)
Wipperfürther Str. 278
51515 Kürten

HRB 66732
Gerichtsstand Amtsgericht Bergisch Gladbach

Telefon +492 268 801 285
Telefax +492 268 801 285
Mobil   +491 577 666 256 5

WWW http://www.axn-software.de
Email info@axn-software.de





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: TimeZone related issues in org.postgresql.jdbc2.TimestampUtils
  2009-09-13 20:31 TimeZone related issues in org.postgresql.jdbc2.TimestampUtils Carsten Klein <carsten.klein@axn-software.de>
@ 2009-09-13 23:22 ` Oliver Jowett <oliver@opencloud.com>
  2009-10-15 18:01   ` Re: TimeZone related issues in org.postgresql.jdbc2.TimestampUtils Carsten Klein (tarent) <carsten.klein@axn-software.de>
  2009-10-16 22:57   ` Re: TimeZone related issues in org.postgresql.jdbc2.TimestampUtils Oliver Jowett <oliver@opencloud.com>
  0 siblings, 2 replies; 4+ messages in thread

From: Oliver Jowett @ 2009-09-13 23:22 UTC (permalink / raw)
  To: carsten.klein@axn-software.de; +Cc: pgsql-jdbc

Carsten Klein wrote:
> Hi All,
> 
> in an application that uses TIMESTAMP WITH TIME ZONE as the type for
> certain attributes, we stumbled across the problem that, sometimes, the
> values returned from the database will be adjusted so that the time zone
> offset will be added/subtracted from the actual time stored in the
> database.

Timezone stuff is very picky. Can you provide a standalone testcase so
we can see exactly what's going on?

-O



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: TimeZone related issues in org.postgresql.jdbc2.TimestampUtils
  2009-09-13 20:31 TimeZone related issues in org.postgresql.jdbc2.TimestampUtils Carsten Klein <carsten.klein@axn-software.de>
  2009-09-13 23:22 ` Re: TimeZone related issues in org.postgresql.jdbc2.TimestampUtils Oliver Jowett <oliver@opencloud.com>
@ 2009-10-15 18:01   ` Carsten Klein (tarent) <carsten.klein@axn-software.de>
  1 sibling, 0 replies; 4+ messages in thread

From: Carsten Klein (tarent) @ 2009-10-15 18:01 UTC (permalink / raw)
  To: Oliver Jowett <oliver@opencloud.com>; +Cc: carsten.klein@axn-software.de; pgsql-jdbc


I wonder what had happened to my reply to your inquiry for sending the
standalone test case?

Did you receive that?

If not, could you please inform me so that I can resend it by inlining the
test case. The last time I did send it as an attachment...

Regards

Carsten


> Carsten Klein wrote:
>> Hi All,
>>
>> in an application that uses TIMESTAMP WITH TIME ZONE as the type for
>> certain attributes, we stumbled across the problem that, sometimes, the
>> values returned from the database will be adjusted so that the time zone
>> offset will be added/subtracted from the actual time stored in the
>> database.
>
> Timezone stuff is very picky. Can you provide a standalone testcase so
> we can see exactly what's going on?
>
> -O
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>







^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: TimeZone related issues in org.postgresql.jdbc2.TimestampUtils
  2009-09-13 20:31 TimeZone related issues in org.postgresql.jdbc2.TimestampUtils Carsten Klein <carsten.klein@axn-software.de>
  2009-09-13 23:22 ` Re: TimeZone related issues in org.postgresql.jdbc2.TimestampUtils Oliver Jowett <oliver@opencloud.com>
@ 2009-10-16 22:57   ` Oliver Jowett <oliver@opencloud.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Oliver Jowett @ 2009-10-16 22:57 UTC (permalink / raw)
  To: c.klein@tarent.de; +Cc: pgsql-jdbc

Carsten Klein (tarent) wrote:
> Attached you find a stand alone test case. I have included a slightly
> modified version of the original TimestampUtils in the jdbc2 package of
> the PostgreSQL JDBC driver.

Do you have a standalone testcase that uses normal JDBC methods and 
shows the problem as an application would see it.

TimestampUtils is an internal class that's not designed to be used 
directly. Its behaviour is fairly closely tied to the server's timestamp 
behaviour and exactly how the rest of the driver uses it.

What we are really interested in is a testcase that shows a problem at 
the JDBC level.

-O



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2009-10-16 22:57 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-09-13 20:31 TimeZone related issues in org.postgresql.jdbc2.TimestampUtils Carsten Klein <carsten.klein@axn-software.de>
2009-09-13 23:22 ` Oliver Jowett <oliver@opencloud.com>
2009-10-15 18:01   ` Carsten Klein (tarent) <carsten.klein@axn-software.de>
2009-10-16 22:57   ` Oliver Jowett <oliver@opencloud.com>

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