You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2010/09/21 18:24:14 UTC

svn commit: r999485 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DateTimeTest.java

Author: kahatlen
Date: Tue Sep 21 16:24:14 2010
New Revision: 999485

URL: http://svn.apache.org/viewvc?rev=999485&view=rev
Log:
DERBY-4626: Timestamp truncated when converted to string with explicit calendar

Added a test case. The bug was fixed as part of DERBY-4625.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DateTimeTest.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DateTimeTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DateTimeTest.java?rev=999485&r1=999484&r2=999485&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DateTimeTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DateTimeTest.java Tue Sep 21 16:24:14 2010
@@ -30,6 +30,7 @@ import java.sql.Statement;
 import java.sql.Time;
 import java.sql.Timestamp;
 import java.util.Calendar;
+import java.util.TimeZone;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -915,6 +916,35 @@ public final class DateTimeTest extends 
     }
 
     /**
+     * Test that conversion from timestamp to string is correct when a
+     * calendar is specified. Specifically, verify that the full nanosecond
+     * resolution is used and that the converted timestamp is not rounded to
+     * microsecond resolution. Regression test case for DERBY-4626.
+     */
+    public void testConvertToStringWithCalendar() throws SQLException {
+        PreparedStatement ps =
+                prepareStatement("values cast(? as varchar(29))");
+
+        // Generate a timestamp representing 2010-09-01 20:31:40.123456789 GMT
+        Timestamp ts = new Timestamp(1283373100000L);
+        ts.setNanos(123456789);
+
+        // Array of (timezone, timestamp string) pairs representing a timezone
+        // with which to test and the expected timestamp string produced.
+        String[][] testData = {
+            { "GMT", "2010-09-01 20:31:40.123456789" },
+            { "Europe/Oslo", "2010-09-01 22:31:40.123456789" },
+        };
+
+        for (int i = 0; i < testData.length; i++) {
+            Calendar cal = Calendar.getInstance(
+                    TimeZone.getTimeZone(testData[i][0]));
+            ps.setTimestamp(1, ts, cal);
+            JDBC.assertSingleValueResultSet(ps.executeQuery(), testData[i][1]);
+        }
+    }
+
+    /**
      * Regression test case for DERBY-4621, which caused the conversion of
      * timestamp and time values to varchar to generate wrong results when
      * a Calendar object was supplied.