fixed bug reported by Wolfgang Winter [email protected] where historic timestamps...
authorBarry Lind
Mon, 24 Jun 2002 04:53:05 +0000 (04:53 +0000)
committerBarry Lind
Mon, 24 Jun 2002 04:53:05 +0000 (04:53 +0000)
src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java
src/interfaces/jdbc/org/postgresql/jdbc2/Array.java
src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java

index a7d0389d56000035b2e4bca130baac7cf5594dc9..11b3e70a56cbc3ac02e309ba5ced58a7bd8537a3 100644 (file)
@@ -566,17 +566,25 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
            }
            else
            {
-               df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+               //if type is timestamptz then data is in GMT, else it is in local timezone
+               if (fields[columnIndex - 1].getPGType().equals("timestamptz")) {
+               sbuf.append(" GMT");
+               df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z");
+               } else {
+                                df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+               }
            }
        }
        else if (slen == 19)
        {
            // No tz or fractional second info. 
-           // I'm not sure if it is
-           // possible to have a string in this format, as pg
-           // should give us tz qualified timestamps back, but it was
-           // in the old code, so I'm handling it for now.
+           // if type is timestamptz then data is in GMT, else it is in local timezone
+           if (fields[columnIndex - 1].getPGType().equals("timestamptz")) {
+           sbuf.append(" GMT");
+           df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
+           } else {
            df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+           }
        }
        else
        {
index 90b56eb92d890aaab781c4584e94e39905f46827..042a6f406975fd83dbcced9206409e7830f8b942 100644 (file)
@@ -172,7 +172,7 @@ public class Array implements java.sql.Array
                retVal = new Timestamp[ count ];
                StringBuffer sbuf = null;
                for ( ; count > 0; count-- )
-                   ((java.sql.Timestamp[])retVal)[i++] = ResultSet.toTimestamp( arrayContents[(int)index++], rs );
+                   ((java.sql.Timestamp[])retVal)[i++] = ResultSet.toTimestamp( arrayContents[(int)index++], rs, getBaseTypeName() );
                break;
 
                // Other datatypes not currently supported.  If you are really using other types ask
index ce6daf69a9066aeec64cf76f063a6e7b16d4fb21..e30849bbe6b96935e8fe725c512b2412d6dd655f 100644 (file)
@@ -401,7 +401,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
     */
    public Timestamp getTimestamp(int columnIndex) throws SQLException
    {
-       return toTimestamp( getString(columnIndex), this );
+       return toTimestamp( getString(columnIndex), this, fields[columnIndex-1].getPGType() );
    }
 
    /*
@@ -1660,7 +1660,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
    *
    * @throws SQLException if there is a problem parsing s.
    **/
-   public static Timestamp toTimestamp(String s, ResultSet resultSet)
+   public static Timestamp toTimestamp(String s, ResultSet resultSet, String pgDataType)
    throws SQLException
    {
        if (s == null)
@@ -1735,18 +1735,26 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
                }
                else
                {
-                   // Just found fractional seconds but no timezone.
+                   // Just found fractional seconds but no timezone.
+                   //If timestamptz then we use GMT, else local timezone
+                           if (pgDataType.equals("timestamptz")) {
+                       resultSet.sbuf.append(" GMT");
+                   df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z");
+                       } else {
                    df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+                       }
                }
            }
            else if (slen == 19)
            {
-               // No tz or fractional second info.
-               // I'm not sure if it is
-               // possible to have a string in this format, as pg
-               // should give us tz qualified timestamps back, but it was
-               // in the old code, so I'm handling it for now.
+               // No tz or fractional second info.
+               //If timestamptz then we use GMT, else local timezone
+                   if (pgDataType.equals("timestamptz")) {
+               resultSet.sbuf.append(" GMT");
+               df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
+               } else {
                df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+               }
            }
            else
            {