harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From qi...@apache.org
Subject svn commit: r832980 - in /harmony/enhanced/classlib/trunk/modules/sql/src: main/java/java/sql/Timestamp.java test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
Date Thu, 05 Nov 2009 03:17:11 GMT
Author: qiuxx
Date: Thu Nov  5 03:17:08 2009
New Revision: 832980

URL: http://svn.apache.org/viewvc?rev=832980&view=rev
Log:
java.sql.Timestamp.compareTo(Date)'s parameter may be not a Timestamp instance but just java.util.Date,
in which case it should be handled separately

Modified:
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Timestamp.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Timestamp.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Timestamp.java?rev=832980&r1=832979&r2=832980&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Timestamp.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Timestamp.java Thu
Nov  5 03:17:08 2009
@@ -193,8 +193,22 @@
      *             if the supplied object is not a {@code Timestamp} object.
      */
     @Override
-    public int compareTo(Date theObject) throws ClassCastException {
-        return this.compareTo((Timestamp) theObject);
+    public int compareTo(Date theObject) {
+        if(theObject instanceof Timestamp){
+            return this.compareTo((Timestamp)theObject);
+        }
+        
+        if (this.getTime() < theObject.getTime()) {
+            return -1;
+        }
+        if (this.getTime() > theObject.getTime()) {
+            return 1;
+        }
+        
+        if (this.getNanos() % 1000000 > 0) {
+            return 1;
+        }
+        return 0;
     }
 
     /**

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java?rev=832980&r1=832979&r2=832980&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
Thu Nov  5 03:17:08 2009
@@ -642,22 +642,17 @@
             assertEquals(0, theTimestamp.compareTo(theTimestamp2));
         } // end for
 
-        Date nastyTest = new Date();
-        Timestamp theTimestamp = new Timestamp(TIME_ARRAY[1]);
-        try {
-            theTimestamp.compareTo(nastyTest);
-            // It throws ClassCastException in JDK 1.5.0_06 but in 1.5.0_07 it
-            // does not throw the expected exception.
-            fail("testCompareToObject: Did not get expected ClassCastException");
-        } catch (ClassCastException e) {
-            // Should get here
-            /*
-             * System.out.println("testCompareToObject: ClassCastException as
-             * expected"); System.out.println("Exception message: " +
-             * e.getMessage());
-             */
-        } // end try
-
+        Timestamp timestamp = new Timestamp(1000000);
+        Date date = new Date(1000000);
+        
+        assertEquals(0, timestamp.compareTo(date));
+        timestamp.setNanos(10);
+        assertEquals(1, timestamp.compareTo(date));
+        
+        long time = System.currentTimeMillis();
+        Date date2 = new Date(time);
+        Timestamp timestamp2 = new Timestamp(date2.getTime());
+        assertEquals(0, timestamp2.compareTo(date2));
     } // end method testcompareToObject
 
     /**



Mime
View raw message