X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B8A5E52889 for ; Thu, 26 May 2005 05:19:53 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 62126-08 for ; Thu, 26 May 2005 08:19:52 +0000 (GMT) Received: from keghouse.net (keghouse.net [150.101.20.202]) by svr1.postgresql.org (Postfix) with ESMTP id AC2A65285B for ; Thu, 26 May 2005 05:19:50 -0300 (ADT) Received: by keghouse.net (Postfix, from userid 50008) id 44EC94AE0F; Thu, 26 May 2005 17:49:49 +0930 (CST) Date: Thu, 26 May 2005 17:49:49 +0930 From: "Samuel L. Bronkowitz" To: pgsql-jdbc@postgresql.org Subject: Fractional timezone bug + patch Message-ID: <20050526081949.GA98221@keghouse.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.1i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200505/116 X-Sequence-Number: 12947 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;