Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.6.9, 1.7.10, 1.8.0
-
Fix Version/s: 1.8.5, 2.0-beta-2
-
Component/s: groovy-jdk
-
Labels:None
-
Environment:This bug appears to be platform and JDK independant.
-
Patch Submitted:Yes
-
Number of attachments :
Description
The following code:
def d = new Date() def t = new java.sql.Timestamp(d.getTime()) println t.class t = t + 1 println t.class
Produces the following output:
class java.sql.Timestamp
class java.util.Date
This behavior is unexpected, and is causing us a small problem. The fix would be to change the org.codehaus.groovy.runtime.DateGroovyMethods.plus(Date,int) method to be as follows:
public static Date plus(Date self, int days) {
Calendar calendar = (Calendar) Calendar.getInstance().clone();
calendar.setTime(self);
calendar.add(Calendar.DAY_OF_YEAR, days);
if (self instanceof java.sql.Timestamp) {
java.sql.Timestamp ts = new java.sql.Timestamp(calendar.getTime().getTime());
ts.setNanos(((java.sql.Timestamp)self).getNanos());
return ts;
}
return calendar.getTime();
}