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();
}
Activity
blackdrag blackdrag
made changes -
| Field | Original Value | New Value |
|---|---|---|
| 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(); } |
The following code:
{code:Java} def d = new Date() def t = new java.sql.Timestamp(d.getTime()) println t.class t = t + 1 println t.class {code} 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: {code:Java} 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(); } {code} |
blackdrag blackdrag
made changes -
| Patch Submitted | [Yes] |
Roshan Dawrani
made changes -
| Assignee | Roshan Dawrani [ roshandawrani ] |
Roshan Dawrani
made changes -
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Fix Version/s | 2.0-beta-2 [ 18072 ] | |
| Fix Version/s | 1.8.5 [ 18071 ] | |
| Resolution | Fixed [ 1 ] |
Paul King
made changes -
| Status | Resolved [ 5 ] | Closed [ 6 ] |
fixed code tags