Skip site navigation (1) Skip section navigation (2)

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: (view raw, whole thread or download thread mbox)
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/       2005-02-15 19:01:47.000000000 +1030
+++ org/postgresql/jdbc2/    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;

pgsql-jdbc by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group