harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chen Shunfei (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-4907) [classlib][luni] Calendar.get(Calendar.WEEK_OF_MONTH)
Date Tue, 09 Oct 2007 02:29:50 GMT
[classlib][luni] Calendar.get(Calendar.WEEK_OF_MONTH)
-----------------------------------------------------

                 Key: HARMONY-4907
                 URL: https://issues.apache.org/jira/browse/HARMONY-4907
             Project: Harmony
          Issue Type: Bug
          Components: Classlib
         Environment: harmony-jre-579330
WindowXP
            Reporter: Chen Shunfei


Here is the testcase:
import java.util.Calendar;
import java.util.GregorianCalendar;
import junit.framework.TestCase;

public class Test extends TestCase {
	public void testDayOfWeekInMonth() {
		GregorianCalendar c = new GregorianCalendar();
		int minimalDaysInFirstWeek = 2;
		int firstDayOfWeek = Calendar.SUNDAY;
		c.setFirstDayOfWeek(firstDayOfWeek);
		int month = Calendar.DECEMBER;
		int year = 2007;
		int day = 1;
		c.set(year, month, day);
		int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
		int relativeDayOfWeek = (7 + dayOfWeek - firstDayOfWeek) % 7;
		int relativeDayOfFirst = (relativeDayOfWeek - day + 1 + 35) % 7;
		int weekOfFirst = ((7 - relativeDayOfFirst) >= minimalDaysInFirstWeek) ? 1
				: 0;
		int weekOfMonth = (day + relativeDayOfFirst - 1) / 7 + weekOfFirst;
		assertEquals(c.get(Calendar.WEEK_OF_MONTH), weekOfMonth);		
	}
}


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message