From f7b89ac5d9eee2c8a4eb3c7bbe0ad648fef176eb Mon Sep 17 00:00:00 2001 From: Peter Mount Date: Tue, 17 Oct 2000 14:52:01 +0000 Subject: [PATCH] Some more getTimestamp() fixes --- src/interfaces/jdbc/CHANGELOG | 6 +++++- .../jdbc/org/postgresql/jdbc1/ResultSet.java | 18 +++++++++++++++++- .../jdbc/org/postgresql/jdbc2/ResultSet.java | 18 +++++++++++++++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/interfaces/jdbc/CHANGELOG b/src/interfaces/jdbc/CHANGELOG index 84eebc6577..e61acd7df9 100644 --- a/src/interfaces/jdbc/CHANGELOG +++ b/src/interfaces/jdbc/CHANGELOG @@ -1,3 +1,8 @@ +Tue Oct 17 15:35:00 BST 2000 petermount@maidstone.gov.uk + - Changed getTimestamp() again. This time Michael Stephenson's + solution looked far better + than the original solution put in June. + Tue Oct 10 13:12:00 BST 2000 peter@retep.org.uk - DatabaseMetaData.supportsAlterTableWithDropColumn() as psql doesn't support dropping of individual columns @@ -13,7 +18,6 @@ Mon Sep 25 14:22:00 BST 2000 peter@retep.org.uk - Removed the DriverClass kludge. Now the org.postgresql.Driver class is compiled from a template file, and now has both the connection class (ie jdbc1/jdbc2) and the current version's from Makefile.global - - Thu Jul 20 16:30:00 BST 2000 petermount@it.maidstone.gov.uk - Fixed DatabaseMetaData.getTableTypes() diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java index e65cf80b55..e9fc53d96a 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java @@ -462,7 +462,23 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu if(s==null) return null; - SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + // This works, but it's commented out because Michael Stephenson's + // solution is better still: + //SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + // Michael Stephenson's solution: + SimpleDateFormat df = null; + if (s.length()>21 && s.indexOf('.') != -1) { + df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSzzz"); + } else if (s.length()>19 && s.indexOf('.') == -1) { + df = new SimpleDateFormat("yyyy-MM-dd HH:MM:sszzz"); + } else if (s.length()>19 && s.indexOf('.') != -1) { + df = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss.SS"); + } else if (s.length()>10 && s.length()<=18) { + df = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss"); + } else { + df = new SimpleDateFormat("yyyy-MM-dd"); + } try { return new Timestamp(df.parse(s).getTime()); diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java index 5c73b6ed4f..e606a16785 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java @@ -465,7 +465,23 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu if(s==null) return null; - SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + // This works, but it's commented out because Michael Stephenson's + // solution is better still: + //SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + // Michael Stephenson's solution: + SimpleDateFormat df = null; + if (s.length()>21 && s.indexOf('.') != -1) { + df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSzzz"); + } else if (s.length()>19 && s.indexOf('.') == -1) { + df = new SimpleDateFormat("yyyy-MM-dd HH:MM:sszzz"); + } else if (s.length()>19 && s.indexOf('.') != -1) { + df = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss.SS"); + } else if (s.length()>10 && s.length()<=18) { + df = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss"); + } else { + df = new SimpleDateFormat("yyyy-MM-dd"); + } try { return new Timestamp(df.parse(s).getTime()); -- 2.40.0