mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-09 15:27:38 +00:00
ICU-6379 More efficient handleGetMonthLength method for CECalendar
X-SVN-Rev: 26159
This commit is contained in:
parent
9e39b57bf1
commit
b83aa67d3b
2 changed files with 61 additions and 0 deletions
|
@ -186,6 +186,38 @@ abstract class CECalendar extends Calendar {
|
|||
return LIMITS[field][limitType];
|
||||
}
|
||||
|
||||
// (The following method is not called because all existing subclasses
|
||||
// override it.
|
||||
///CLOVER:OFF
|
||||
/**
|
||||
* Return the number of days in the given month of the given extended
|
||||
* year of this calendar system. Subclasses should override this
|
||||
* method if they can provide a more correct or more efficient
|
||||
* implementation than the default implementation in Calendar.
|
||||
* @new ICU 4.4
|
||||
*/
|
||||
protected int handleGetMonthLength(int extendedYear, int month)
|
||||
{
|
||||
|
||||
// The Ethiopian and Coptic calendars have 13 months, 12 of 30 days each and
|
||||
// an intercalary month at the end of the year of 5 or 6 days, depending whether
|
||||
// the year is a leap year or not. The Leap Year follows the same rules as the
|
||||
// Julian Calendar so that the extra month always has six days in the year before
|
||||
// a Julian Leap Year.
|
||||
if ((month + 1) % 13 != 0)
|
||||
{
|
||||
// not intercalary month
|
||||
return 30;
|
||||
}
|
||||
else
|
||||
{
|
||||
// intercalary month 5 days + possible leap day
|
||||
return ((extendedYear % 4) / 3) + 5;
|
||||
}
|
||||
|
||||
}
|
||||
///CLOVER:ON
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Calendar framework
|
||||
//-------------------------------------------------------------------------
|
||||
|
|
|
@ -211,6 +211,35 @@ public class CopticTest extends CalendarTest
|
|||
doTheoreticalLimitsTest(coptic, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for track ticket 6379 - proper reporting of
|
||||
* maximum month lengths
|
||||
*/
|
||||
public void Test6379()
|
||||
{
|
||||
int i;
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(2007, Calendar.JANUARY, 1);
|
||||
CopticCalendar coptic = new CopticCalendar();
|
||||
|
||||
// first twelve months have 30 days
|
||||
for (i = 0; i < 12; i++)
|
||||
{
|
||||
coptic.set(Calendar.MONTH, i);
|
||||
if (30 != coptic.getActualMaximum(Calendar.DAY_OF_MONTH))
|
||||
{
|
||||
errln("30 days not returned for month " + (i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
// test month 13
|
||||
coptic.set(Calendar.MONTH, i);
|
||||
if (5 != coptic.getActualMaximum(Calendar.DAY_OF_MONTH))
|
||||
{
|
||||
errln("5 days not returned for month " + (i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
public void TestCoverage() {
|
||||
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue