From 0380765cc17c7216a11f361c52dc47c157681598 Mon Sep 17 00:00:00 2001
From: Bruce Momjian <bruce@momjian.us>
Date: Mon, 28 May 2001 00:37:00 +0000
Subject: [PATCH] Attached is a patch to fix the problem Thomas mentions below.
  The JDBC driver now correctly handles timezones that are offset fractional
 hours from GMT (ie. -06:30).

Barry Lind
---
 .../jdbc/org/postgresql/jdbc1/ResultSet.java  | 26 +++++++++++++++++--
 .../jdbc/org/postgresql/jdbc2/ResultSet.java  | 22 ++++++++++++++++
 2 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java
index aae8cf6ff26..98af07b0b63 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java
@@ -472,13 +472,35 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
     //so this code strips off timezone info and adds on the GMT+/-...
     //as well as adds a third digit for partial seconds if necessary
     StringBuffer strBuf = new StringBuffer(s);
+
+    //we are looking to see if the backend has appended on a timezone.
+    //currently postgresql will return +/-HH:MM or +/-HH for timezone offset
+    //(i.e. -06, or +06:30, note the expectation of the leading zero for the
+    //hours, and the use of the : for delimiter between hours and minutes)
+    //if the backend ISO format changes in the future this code will
+    //need to be changed as well
     char sub = strBuf.charAt(strBuf.length()-3);
     if (sub == '+' || sub == '-') {
       strBuf.setLength(strBuf.length()-3);
       if (subsecond)  {
-        strBuf = strBuf.append('0').append("GMT").append(s.substring(s.length()-3, s.length())).append(":00");
+        strBuf.append('0').append("GMT").append(s.substring(s.length()-3, s.length())).append(":00");
+      } else {
+        strBuf.append("GMT").append(s.substring(s.length()-3, s.length())).append(":00");
+      }
+    } else if (sub == ':') {
+      //we may have found timezone info of format +/-HH:MM, or there is no
+      //timezone info at all and this is the : preceding the seconds
+      char sub2 = strBuf.charAt(strBuf.length()-5);
+      if (sub2 == '+' || sub2 == '-') {
+        //we have found timezone info of format +/-HH:MM
+        strBuf.setLength(strBuf.length()-5);
+        if (subsecond) {
+          strBuf.append('0').append("GMT").append(s.substring(s.length()-5));
       } else {
-        strBuf = strBuf.append("GMT").append(s.substring(s.length()-3, s.length())).append(":00");
+          strBuf.append("GMT").append(s.substring(s.length()-5));
+        }
+      } else if (subsecond) {
+        strBuf.append('0');
       }
     } else if (subsecond) {
       strBuf = strBuf.append('0');
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java
index 7aebd950b00..2928ab969b3 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java
@@ -484,14 +484,36 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
       sbuf.setLength(0);
       sbuf.append(s);
 
+      //we are looking to see if the backend has appended on a timezone.
+      //currently postgresql will return +/-HH:MM or +/-HH for timezone offset
+      //(i.e. -06, or +06:30, note the expectation of the leading zero for the
+      //hours, and the use of the : for delimiter between hours and minutes)
+      //if the backend ISO format changes in the future this code will
+      //need to be changed as well
       char sub = sbuf.charAt(sbuf.length()-3);
       if (sub == '+' || sub == '-') {
+        //we have found timezone info of format +/-HH
         sbuf.setLength(sbuf.length()-3);
         if (subsecond)  {
           sbuf.append('0').append("GMT").append(s.substring(s.length()-3)).append(":00");
         } else {
           sbuf.append("GMT").append(s.substring(s.length()-3)).append(":00");
         }
+      } else if (sub == ':') {
+        //we may have found timezone info of format +/-HH:MM, or there is no
+        //timezone info at all and this is the : preceding the seconds
+        char sub2 = sbuf.charAt(sbuf.length()-5);
+        if (sub2 == '+' || sub2 == '-') {
+          //we have found timezone info of format +/-HH:MM
+          sbuf.setLength(sbuf.length()-5);
+          if (subsecond)  {
+            sbuf.append('0').append("GMT").append(s.substring(s.length()-5));
+          } else {
+            sbuf.append("GMT").append(s.substring(s.length()-5));
+          }
+        } else if (subsecond) {
+          sbuf.append('0');
+        }
       } else if (subsecond) {
         sbuf.append('0');
       }
-- 
GitLab