GregorianCalendar clone problem
-------------------------------
Key: HARMONY-498
URL: http://issues.apache.org/jira/browse/HARMONY-498
Project: Harmony
Type: Bug
Components: Classlib
Reporter: Mark Hindess
Priority: Minor
The following test code breaks on Harmony. Setting milliseconds to zero alters the day of
the month. Output on RI is:
today time = Tue May 23 14:06:51 BST 2006
yesterday time = Mon May 22 14:06:51 BST 2006
day of month before resetting milliseconds = 23
day of month after resetting milliseconds = 23
time before resetting seconds = Tue May 23 14:06:51 BST 2006
time after resetting seconds = Tue May 23 14:06:00 BST 2006
Output on Harmony is:
today time = Tue May 23 13:59:39 BST 2006
yesterday time = Mon May 22 13:59:39 BST 2006
day of month before resetting milliseconds = 23
day of month after resetting milliseconds = 22
time before resetting seconds = Tue May 23 13:59:39 BST 2006
time after resetting seconds = Mon May 22 13:59:00 BST 2006
I suspect it might have something to do with the cachedFields?
import java.util.TimeZone;
import java.util.Calendar;
public class Test2 {
public static void main(String[] args) {
Calendar today = Calendar.getInstance();
System.err.println("today time = "+today.getTime());
Calendar yesterday = (Calendar)today.clone(); // copy not deep enough?
yesterday.add(Calendar.DATE, -1);
System.err.println("yesterday time = "+yesterday.getTime());
Calendar broken = (Calendar)today.clone();
System.err.println("day of month before resetting milliseconds = "+
broken.get(Calendar.DAY_OF_MONTH));
broken.set(Calendar.MILLISECOND, 0);
System.err.println("day of month after resetting milliseconds = "+
broken.get(Calendar.DAY_OF_MONTH));
System.err.println("time before resetting seconds = "+broken.getTime());
broken.set(Calendar.SECOND, 0);
System.err.println("time after resetting seconds = "+broken.getTime());
}
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
|