Fractional timezone bug + patch

From: "Samuel L(dot) Bronkowitz" <slb(at)keghouse(dot)net>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Fractional timezone bug + patch
Date: 2005-05-26 08:19:49
Message-ID: 20050526081949.GA98221@keghouse.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hi. I'm in Adelaide, Australia, where the standard timezone is +9:30.
A couple of hours ago I stumbled across a JDBC bug when calling
getTimestamp() on a ResultSet: the fractional part of the timezone was
being dropped, so the returned timestamp was in +9. Therefore, when
displayed in the VM's timezone of +9:30, the timestamp had 30 minutes
tacked on and was thus 30 minutes into the future.

A perusal of the archives finds that a fractional timezone bug was
fixed in 2001, however a lot of the code seems to have been rewritten
between then and now.

A quick look over the driver source code found the bug: a simple
string-processing flaw. Two "sep = ..." and "end = ..." lines were in
the wrong order (see below), thus the code skipped past the ":" and
missed the fractional offset. A patch to the latest CVS is below.

- Samuel

--- org/postgresql/jdbc2/TimestampUtils.java.orig 2005-02-15 19:01:47.000000000 +1030
+++ org/postgresql/jdbc2/TimestampUtils.java 2005-05-26 17:37:43.000000000 +0930
@@ -120,12 +120,12 @@

end = firstNonDigit(s, start);
int tzhr = number(s, start, end);
start = end + 1;

- end = firstNonDigit(s, start);
sep = charAt(s, end);
+ end = firstNonDigit(s, start);

int tzmin = 0;
if (sep == ':') {
tzmin = number(s, start, end);
start = end + 1;

Browse pgsql-jdbc by date

  From Date Subject
Next Message Giuseppe Sacco 2005-05-26 08:43:51 Re: DatabaseMetaData.getExtraNameCharacters
Previous Message Oliver Jowett 2005-05-26 05:24:26 Re: BIGINT <-> java.lang.String auto cast