Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.6.9, 1.7.10, 1.8.0
-
None
-
This bug appears to be platform and JDK independant.
-
Patch
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(); }