Commit c50bf019 authored by Barry Lind's avatar Barry Lind

fixed bug reported by Wolfgang Winter w.winter@logitags.com where historic...

fixed bug reported by Wolfgang Winter w.winter@logitags.com where historic timestamps which do not have timezone info were being interpreted in local timezone instead of GMT.  Also added a check to support timestamp vs. timestamptz in this code
parent 68913b0f
...@@ -566,18 +566,26 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu ...@@ -566,18 +566,26 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
} }
else else
{ {
//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"); df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
} }
} }
}
else if (slen == 19) else if (slen == 19)
{ {
// No tz or fractional second info. // No tz or fractional second info.
// I'm not sure if it is // if type is timestamptz then data is in GMT, else it is in local timezone
// possible to have a string in this format, as pg if (fields[columnIndex - 1].getPGType().equals("timestamptz")) {
// should give us tz qualified timestamps back, but it was sbuf.append(" GMT");
// in the old code, so I'm handling it for now. df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
} else {
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
} }
}
else else
{ {
// We must just have a date. This case is // We must just have a date. This case is
......
...@@ -172,7 +172,7 @@ public class Array implements java.sql.Array ...@@ -172,7 +172,7 @@ public class Array implements java.sql.Array
retVal = new Timestamp[ count ]; retVal = new Timestamp[ count ];
StringBuffer sbuf = null; StringBuffer sbuf = null;
for ( ; count > 0; count-- ) 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; break;
// Other datatypes not currently supported. If you are really using other types ask // Other datatypes not currently supported. If you are really using other types ask
......
...@@ -401,7 +401,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu ...@@ -401,7 +401,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
*/ */
public Timestamp getTimestamp(int columnIndex) throws SQLException 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 ...@@ -1660,7 +1660,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
* *
* @throws SQLException if there is a problem parsing s. * @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 throws SQLException
{ {
if (s == null) if (s == null)
...@@ -1736,18 +1736,26 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu ...@@ -1736,18 +1736,26 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
else 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"); df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
} }
} }
}
else if (slen == 19) else if (slen == 19)
{ {
// No tz or fractional second info. // No tz or fractional second info.
// I'm not sure if it is //If timestamptz then we use GMT, else local timezone
// possible to have a string in this format, as pg if (pgDataType.equals("timestamptz")) {
// should give us tz qualified timestamps back, but it was resultSet.sbuf.append(" GMT");
// in the old code, so I'm handling it for now. df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
} else {
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
} }
}
else else
{ {
// We must just have a date. This case is // We must just have a date. This case is
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment