* handling in the Hebrew calendar because of the pattern of leap
* years.
*/
public void TestMonthMovement() {
try{
HebrewCalendar cal = new HebrewCalendar();
// Leap years are:
// 3 6 8 11 14 17 19 (and so on - 19-year cycle)
// We can't test complete() on some lines below because of ADAR_1 -- if
// the calendar is set to ADAR_1 on a non-leap year, the result is undefined.
int[] DATA = {
// m1/y1 - month/year before (month is 1-based)
// delta - amount to add to month field
// m2/y2 - month/year after add(MONTH, delta)
// m3/y3 - month/year after set(MONTH, m1+delta)
//m1 y1 delta m2 y2 m3 y3
10, 2, +24, 9, 4, 9, 4,
10, 2, +60, 8, 7, 8, 7,
1 , 2, +12, 1, 3, 13, 2, //*set != add; also see '*' below
3 , 18, -24, 4, 16, 4, 16,
1 , 6, -24, 1, 4, 1, 4,
4 , 3, +2, 6, 3, 6, 3, // Leap year - no skip 4,5,6,7,8
8 , 3, -2, 6, 3, 6, 3, // Leap year - no skip
4 , 2, +2, 7, 2, 7, 2, // Skip leap month 4,5,(6),7,8
8 , 2, -2, 5, 2, 7, 2, //*Skip leap month going backward
};
for (int i=0; i<DATA.length; ) {
int m = DATA[i++], y = DATA[i++];
int monthDelta = DATA[i++];
int m2 = DATA[i++], y2 = DATA[i++];
int m3 = DATA[i++], y3 = DATA[i++];
int mact, yact;
cal.clear();
cal.set(Calendar.YEAR, y);
cal.set(Calendar.MONTH, m-1);
cal.add(Calendar.MONTH, monthDelta);
yact = cal.get(Calendar.YEAR); mact = cal.get(Calendar.MONTH) + 1;
if (y2 != yact || m2 != mact) {
errln("Fail: " + m + "/" + y +
" -> add(MONTH, " + monthDelta + ") -> " +
mact + "/" + yact + ", expected " +
m2 + "/" + y2);
cal.clear();
cal.set(Calendar.YEAR, y);
cal.set(Calendar.MONTH, m-1);
logln("Start: " + m + "/" + y);
int delta = monthDelta > 0 ? 1 : -1;
for (int c=0; c!=monthDelta; c+=delta) {
cal.add(Calendar.MONTH, delta);
logln("+ " + delta + " MONTH -> " +
(cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.YEAR));
}
}
cal.clear();
cal.set(Calendar.YEAR, y);
cal.set(Calendar.MONTH, m + monthDelta - 1);
yact = cal.get(Calendar.YEAR); mact = cal.get(Calendar.MONTH) + 1;
if (y3 != yact || m3 != mact) {
errln("Fail: " + (m+monthDelta) + "/" + y +
" -> complete() -> " +
mact + "/" + yact + ", expected " +
m3 + "/" + y3);