Some more getTimestamp() fixes
authorPeter Mount
Tue, 17 Oct 2000 14:52:01 +0000 (14:52 +0000)
committerPeter Mount
Tue, 17 Oct 2000 14:52:01 +0000 (14:52 +0000)
src/interfaces/jdbc/CHANGELOG
src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java
src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java

index 84eebc6577b821d7d7db0c72c0959bd1b3aae9b0..e61acd7df93b7bd3548f7fcc0a94c3937d163b77 100644 (file)
@@ -1,3 +1,8 @@
+Tue Oct 17 15:35:00 BST 2000 [email protected]
+   - 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 [email protected]
    - DatabaseMetaData.supportsAlterTableWithDropColumn() as psql doesn't
      support dropping of individual columns
@@ -13,7 +18,6 @@ Mon Sep 25 14:22:00 BST 2000 [email protected]
    - 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 [email protected]
    - Fixed DatabaseMetaData.getTableTypes()
index e65cf80b55b2b6a48512c2d3c58346108b057573..e9fc53d96a85bec33dd6fda20557fdff34ebf5f1 100644 (file)
@@ -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());
index 5c73b6ed4f07ad4bad39b92d37e507eee853d16d..e606a16785da641ec8bf2c58853ab70d586bfa67 100644 (file)
@@ -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());