@@ -1554,14 +1554,26 @@ public static java.sql.Date toDate(String s) throws SQLException
15541554{
15551555if (s ==null )
15561556return null ;
1557- return java .sql .Date .valueOf (s );
1557+ // length == 10: SQL Date
1558+ // length > 10: SQL Timestamp, assumes PGDATESTYLE=ISO
1559+ try {
1560+ return java .sql .Date .valueOf ((s .length () ==10 ) ?s :s .substring (0 ,10 ));
1561+ }catch (NumberFormatException e ) {
1562+ throw new PSQLException ("postgresql.res.baddate" ,s );
1563+ }
15581564}
15591565
15601566public static Time toTime (String s )throws SQLException
15611567{
15621568if (s ==null )
15631569return null ;// SQL NULL
1564- return java .sql .Time .valueOf (s );
1570+ // length == 8: SQL Time
1571+ // length > 8: SQL Timestamp
1572+ try {
1573+ return java .sql .Time .valueOf ((s .length () ==8 ) ?s :s .substring (11 ,19 ));
1574+ }catch (NumberFormatException e ) {
1575+ throw new PSQLException ("postgresql.res.badtime" ,s );
1576+ }
15651577}
15661578
15671579public static Timestamp toTimestamp (String s ,ResultSet resultSet )throws SQLException
@@ -1598,9 +1610,17 @@ public static Timestamp toTimestamp(String s, ResultSet resultSet) throws SQLExc
15981610resultSet .sbuf .setLength (0 );
15991611resultSet .sbuf .append (s );
16001612
1613+ //we are looking to see if the backend has appended on a timezone.
1614+ //currently postgresql will return +/-HH:MM or +/-HH for timezone offset
1615+ //(i.e. -06, or +06:30, note the expectation of the leading zero for the
1616+ //hours, and the use of the : for delimiter between hours and minutes)
1617+ //if the backend ISO format changes in the future this code will
1618+ //need to be changed as well
16011619char sub =resultSet .sbuf .charAt (resultSet .sbuf .length () -3 );
16021620if (sub =='+' ||sub =='-' )
16031621{
1622+ //we have found timezone info of format +/-HH
1623+
16041624resultSet .sbuf .setLength (resultSet .sbuf .length () -3 );
16051625if (subsecond )
16061626{
@@ -1610,6 +1630,23 @@ public static Timestamp toTimestamp(String s, ResultSet resultSet) throws SQLExc
16101630{
16111631resultSet .sbuf .append ("GMT" ).append (s .substring (s .length () -3 )).append (":00" );
16121632}
1633+ }else if (sub ==':' ) {
1634+ //we may have found timezone info of format +/-HH:MM, or there is no
1635+ //timezone info at all and this is the : preceding the seconds
1636+ char sub2 =resultSet .sbuf .charAt (resultSet .sbuf .length ()-5 );
1637+ if (sub2 =='+' ||sub2 =='-' )
1638+ {
1639+ //we have found timezone info of format +/-HH:MM
1640+ resultSet .sbuf .setLength (resultSet .sbuf .length ()-5 );
1641+ if (subsecond )
1642+ {
1643+ resultSet .sbuf .append ('0' ).append ("GMT" ).append (s .substring (s .length ()-5 ));
1644+ }else {
1645+ resultSet .sbuf .append ("GMT" ).append (s .substring (s .length ()-5 ));
1646+ }
1647+ }else if (subsecond ) {
1648+ resultSet .sbuf .append ('0' );
1649+ }
16131650}
16141651else if (subsecond )
16151652{