[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug classpath/27362] New: Call to java.util.Calendar#clear() may discar
From: |
kiyun dot roe at active-endpoints dot com |
Subject: |
[Bug classpath/27362] New: Call to java.util.Calendar#clear() may discard java.util.Calendar#add() change |
Date: |
30 Apr 2006 04:20:22 -0000 |
A call to java.util.Calendar#clear() forces the Calendar object to recalculate
the time from the Calendar fields. However, java.util.Calendar#add() does not
always record the change to the field (recording just the effect on the
millis). So, calling clear() after add() may discard a change that was
introduced by add().
In the test case below, the calculated yesterdayStart is the same as
todayStart, because the effect of calendar.add(Calendar.DATE, -1) islost.
public void testPreviousDate) throws Exception
{
Calendar calendar = Calendar.getInstance();
Date now = new Date();
// Calculate the start of today.
calendar.setTime(now);
calendar.clear(Calendar.HOUR);
calendar.clear(Calendar.MINUTE);
calendar.clear(Calendar.SECOND);
calendar.clear(Calendar.MILLISECOND);
Date todayStart = calendar.getTime();
// Calculate the start of yesterday.
calendar.setTime(now);
calendar.add(Calendar.DATE, -1); // this change is lost
calendar.clear(Calendar.HOUR);
calendar.clear(Calendar.MINUTE);
calendar.clear(Calendar.SECOND);
calendar.clear(Calendar.MILLISECOND);
Date yesterdayStart = calendar.getTime();
assertTrue(yesterdayStart.before(todayStart));
}
--
Summary: Call to java.util.Calendar#clear() may discard
java.util.Calendar#add() change
Product: classpath
Version: 0.90
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: classpath
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: kiyun dot roe at active-endpoints dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27362
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Bug classpath/27362] New: Call to java.util.Calendar#clear() may discard java.util.Calendar#add() change,
kiyun dot roe at active-endpoints dot com <=