ICU-6033 IS_LEAP_MONTH moved from ChineseCalendar to Calendar

X-SVN-Rev: 26443
This commit is contained in:
Jason Spieth 2009-07-27 17:09:00 +00:00
parent 1e5826f41a
commit 252149b02a
9 changed files with 44 additions and 45 deletions

View File

@ -939,12 +939,19 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
*/
public static final int MILLISECONDS_IN_DAY = 21;
/**
* Field indicating whether or not the current month is a leap month.
* Should have a value of 0 for non-leap months, and 1 for leap months.
* @draft ICU 4.4
*/
public static final int IS_LEAP_MONTH = 22;
/**
* The number of fields defined by this class. Subclasses may define
* addition fields starting with this number.
* @stable ICU 2.0
*/
protected static final int BASE_FIELD_COUNT = 22;
protected static final int BASE_FIELD_COUNT = 23;
/**
* The maximum number of fields possible. Subclasses must not define
@ -1546,7 +1553,8 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
(1 << MONTH) |
(1 << DAY_OF_MONTH) |
(1 << DAY_OF_YEAR) |
(1 << EXTENDED_YEAR);
(1 << EXTENDED_YEAR) |
(1 << IS_LEAP_MONTH);
for (int i=BASE_FIELD_COUNT; i<fields.length; ++i) {
mask |= (1 << i);
}
@ -2328,7 +2336,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
* of the DAY_OF_YEAR or MONTH depends only on the year and supra-year
* fields. The actual maximum of the DAY_OF_MONTH depends, in
* addition, on the MONTH field and any other fields at that
* granularity (such as ChineseCalendar.IS_LEAP_MONTH). The
* granularity (such as IS_LEAP_MONTH). The
* DAY_OF_WEEK_IN_MONTH field does not depend on the current
* DAY_OF_WEEK; it returns the maximum for any day of week in the
* current month. Likewise for the WEEK_OF_MONTH and WEEK_OF_YEAR
@ -3887,6 +3895,8 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
{/* */}, // EXTENDED_YEAR
{ -0x7F000000, -0x7F000000, 0x7F000000, 0x7F000000 }, // JULIAN_DAY
{ 0, 0, 24*ONE_HOUR-1, 24*ONE_HOUR-1 }, // MILLISECONDS_IN_DAY
{ 0, 0, 1, 1 }, // IS_LEAP_MONTH
};
/**
@ -3936,6 +3946,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
case DOW_LOCAL:
case JULIAN_DAY:
case MILLISECONDS_IN_DAY:
case IS_LEAP_MONTH:
return LIMITS[field][limitType];
case WEEK_OF_MONTH:

View File

@ -27,10 +27,6 @@ import com.ibm.icu.text.DateFormat;
* which month is a leap month depends on the relative movements of the sun
* and moon.
*
* <p>This class defines one addition field beyond those defined by
* <code>Calendar</code>: The <code>IS_LEAP_MONTH</code> field takes the
* value of 0 for normal months, or 1 for leap months.
*
* <p>All astronomical computations are performed with respect to a time
* zone of GMT+8:00 and a longitude of 120 degrees east. Although some
* calendars implement a historically more accurate convention of using
@ -162,7 +158,7 @@ public class ChineseCalendar extends Calendar {
* @param year The value used to set the calendar's {@link #YEAR YEAR} time field.
* @param month The value used to set the calendar's {@link #MONTH MONTH} time field.
* The value is 0-based. e.g., 0 for January.
* @param isLeapMonth The value used to set the Chiense calendar's (@link #IS_LEAP_MONTH)
* @param isLeapMonth The value used to set the Chinese calendar's (@link #IS_LEAP_MONTH)
* time field.
* @param date The value used to set the calendar's {@link #DATE DATE} time field.
* @stable ICU 4.0
@ -289,25 +285,13 @@ public class ChineseCalendar extends Calendar {
* Should have a value of 0 for non-leap months, and 1 for leap months.
* @stable ICU 2.8
*/
public static int IS_LEAP_MONTH = BASE_FIELD_COUNT;
// public static int IS_LEAP_MONTH = BASE_FIELD_COUNT;
/**
* Count of fields in this class.
*/
private static final int FIELD_COUNT = IS_LEAP_MONTH + 1;
//------------------------------------------------------------------
// Calendar framework
//------------------------------------------------------------------
/**
* Override Calendar to allocate our additional field.
* @stable ICU 2.8
*/
protected int[] handleCreateFields() {
return new int[FIELD_COUNT];
}
/**
* Array defining the limits of field values for this class. Field
* limits which are invariant with respect to calendar system and

View File

@ -1353,7 +1353,8 @@ public class CalendarRegression extends com.ibm.icu.dev.test.TestFmwk {
(op==0 ? "add" : "roll"));
for (int field=0; field < cal.getFieldCount(); ++field) {
if (field != Calendar.ZONE_OFFSET &&
field != Calendar.DST_OFFSET) {
field != Calendar.DST_OFFSET &&
field != Calendar.IS_LEAP_MONTH ) {
for (int j=0; j<fieldsList.length; ++j) {
int fields[] = fieldsList[j];
cal.clear();

View File

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 1996-2008, International Business Machines Corporation and *
* Copyright (C) 1996-2009, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -425,7 +425,7 @@ public class CalendarTest extends TestFmwk {
if (cal instanceof ChineseCalendar) {
return "" + cal.get(Calendar.EXTENDED_YEAR) + "/" +
(cal.get(Calendar.MONTH)+1) +
(cal.get(ChineseCalendar.IS_LEAP_MONTH)==1?"(leap)":"") + "/" +
(cal.get(Calendar.IS_LEAP_MONTH)==1?"(leap)":"") + "/" +
cal.get(Calendar.DATE) + " (" + day + ", time=" + cal.getTimeInMillis() + ")";
}
return ymdToString(cal.get(Calendar.EXTENDED_YEAR),

View File

@ -1,5 +1,5 @@
/*********************************************************************
* Copyright (C) 2000-2008, International Business Machines Corporation and
* Copyright (C) 2000-2009, International Business Machines Corporation and
* others. All Rights Reserved.
*********************************************************************
*/
@ -95,7 +95,7 @@ public class ChineseTest extends CalendarTest {
cal.setTime(date);
int y = cal.get(Calendar.EXTENDED_YEAR);
int m = cal.get(Calendar.MONTH)+1; // 0-based -> 1-based
int L = cal.get(ChineseCalendar.IS_LEAP_MONTH);
int L = cal.get(Calendar.IS_LEAP_MONTH);
int d = cal.get(Calendar.DAY_OF_MONTH);
int yE = DATA[i++]; // Expected y, m, isLeapMonth, d
int mE = DATA[i++]; // 1-based
@ -123,7 +123,7 @@ public class ChineseTest extends CalendarTest {
cal.clear();
cal.set(Calendar.EXTENDED_YEAR, cyear);
cal.set(Calendar.MONTH, cmonth-1);
cal.set(ChineseCalendar.IS_LEAP_MONTH, cisleapmonth);
cal.set(Calendar.IS_LEAP_MONTH, cisleapmonth);
cal.set(Calendar.DAY_OF_MONTH, cdayofmonth);
Date date = cal.getTime();
buf.setLength(0);
@ -153,7 +153,7 @@ public class ChineseTest extends CalendarTest {
errln("Fail: " + greg.getTime() + " -> " +
cal.get(Calendar.EXTENDED_YEAR) + "/" +
cal.get(Calendar.MONTH) +
(cal.get(ChineseCalendar.IS_LEAP_MONTH)==1?"(leap)":"") +
(cal.get(Calendar.IS_LEAP_MONTH)==1?"(leap)":"") +
"/" + cal.get(Calendar.DAY_OF_MONTH));
}
greg.add(Calendar.DAY_OF_YEAR, 1);
@ -298,7 +298,7 @@ public class ChineseTest extends CalendarTest {
1,0,1, // Expect 1-1
// If we set MONTH only, that should be used
ChineseCalendar.IS_LEAP_MONTH, 1,
Calendar.IS_LEAP_MONTH, 1,
Calendar.DAY_OF_MONTH, 1,
Calendar.MONTH, 3,
END,
@ -306,7 +306,7 @@ public class ChineseTest extends CalendarTest {
// If we set the DOY last, that should take precedence
Calendar.MONTH, 1, // Should ignore
ChineseCalendar.IS_LEAP_MONTH, 1, // Should ignore
Calendar.IS_LEAP_MONTH, 1, // Should ignore
Calendar.DAY_OF_MONTH, 1, // Should ignore
Calendar.DAY_OF_YEAR, 121,
END,
@ -328,7 +328,7 @@ public class ChineseTest extends CalendarTest {
Calendar.MONTH, 3,
Calendar.DAY_OF_MONTH, 1,
Calendar.DAY_OF_YEAR, 5, // Should ignore
ChineseCalendar.IS_LEAP_MONTH, 1,
Calendar.IS_LEAP_MONTH, 1,
END,
4,1,1, // Expect 4*-1
};
@ -348,7 +348,7 @@ public class ChineseTest extends CalendarTest {
int expIsLeapMonth = DATA[i++];
int expDOM = DATA[i++];
int month = cal.get(Calendar.MONTH);
int isLeapMonth = cal.get(ChineseCalendar.IS_LEAP_MONTH);
int isLeapMonth = cal.get(Calendar.IS_LEAP_MONTH);
int dom = cal.get(Calendar.DAY_OF_MONTH);
if (expMonth == month && expIsLeapMonth == isLeapMonth &&
dom == expDOM) {
@ -358,7 +358,7 @@ public class ChineseTest extends CalendarTest {
cal.clear();
cal.set(Calendar.EXTENDED_YEAR, THE_YEAR);
cal.set(Calendar.MONTH, expMonth);
cal.set(ChineseCalendar.IS_LEAP_MONTH, expIsLeapMonth);
cal.set(Calendar.IS_LEAP_MONTH, expIsLeapMonth);
cal.set(Calendar.DAY_OF_MONTH, expDOM);
errln("Fail: " + buf + " => " + s +
"=" + (month+1) + "," + isLeapMonth + "," + dom +
@ -472,7 +472,7 @@ public class ChineseTest extends CalendarTest {
cal.clear();
cal.set(Calendar.EXTENDED_YEAR, test[0]);
cal.set(Calendar.MONTH, test[1]-1);
cal.set(ChineseCalendar.IS_LEAP_MONTH, test[2]);
cal.set(Calendar.IS_LEAP_MONTH, test[2]);
cal.set(Calendar.DAY_OF_MONTH, test[3]);
if (roll) {
cal.roll(test[4], test[5]);
@ -481,7 +481,7 @@ public class ChineseTest extends CalendarTest {
}
if (cal.get(Calendar.EXTENDED_YEAR) != test[6] ||
cal.get(MONTH) != (test[7]-1) ||
cal.get(ChineseCalendar.IS_LEAP_MONTH) != test[8] ||
cal.get(Calendar.IS_LEAP_MONTH) != test[8] ||
cal.get(DATE) != test[9]) {
errln("Fail: " + name + " " +
ymdToString(test[0], test[1]-1, test[2], test[3])
@ -542,7 +542,7 @@ public class ChineseTest extends CalendarTest {
}
// Make sure the given values are properly set
if (cal.get(Calendar.YEAR) != 23 || cal.get(Calendar.MONTH) != Calendar.JULY
|| cal.get(ChineseCalendar.IS_LEAP_MONTH) != 1 || cal.get(Calendar.DATE) != 2
|| cal.get(Calendar.IS_LEAP_MONTH) != 1 || cal.get(Calendar.DATE) != 2
|| cal.get(Calendar.MILLISECONDS_IN_DAY) != 0) {
errln("ChineseCalendar was initialized incorrectly with year,month,isLeapMonth,date");
}
@ -556,7 +556,7 @@ public class ChineseTest extends CalendarTest {
}
// Make sure the given values are properly set
if (cal.get(Calendar.YEAR) != 23 || cal.get(Calendar.MONTH) != Calendar.JULY
|| cal.get(ChineseCalendar.IS_LEAP_MONTH) != 1 || cal.get(Calendar.DATE) != 2
|| cal.get(Calendar.IS_LEAP_MONTH) != 1 || cal.get(Calendar.DATE) != 2
|| cal.get(Calendar.HOUR_OF_DAY) != 12 || cal.get(Calendar.MINUTE) != 34
|| cal.get(Calendar.SECOND) != 56 || cal.get(Calendar.MILLISECOND) != 0) {
errln("ChineseCalendar was initialized incorrectly with year,month,isLeapMonth,date,hour,minute,second");
@ -666,7 +666,7 @@ public class ChineseTest extends CalendarTest {
cc.set(Calendar.MONTH, 0);
// need to set leap month flag off, otherwise, the test case always fails when
// current time is in a leap month
cc.set(ChineseCalendar.IS_LEAP_MONTH, 0);
cc.set(Calendar.IS_LEAP_MONTH, 0);
cc.set(Calendar.DATE, 19);
cc.set(Calendar.HOUR_OF_DAY, 0);
cc.set(Calendar.MINUTE, 0);

View File

@ -1,6 +1,6 @@
/**
*******************************************************************************
* Copyright (C) 2001-2004, International Business Machines Corporation and *
* Copyright (C) 2001-2009, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -35,7 +35,7 @@ public class ChineseTestCase extends TestCase {
set(Calendar.ERA, era);
set(Calendar.YEAR, year);
set(Calendar.MONTH, month - 1);
set(ChineseCalendar.IS_LEAP_MONTH, isLeapMonth?1:0);
set(Calendar.IS_LEAP_MONTH, isLeapMonth?1:0);
set(Calendar.DAY_OF_MONTH, dayOfMonth);
set(Calendar.DAY_OF_WEEK, dayOfWeek);
}
@ -47,7 +47,7 @@ public class ChineseTestCase extends TestCase {
return dowToString(get(Calendar.DAY_OF_WEEK)) +
get(Calendar.YEAR) + "of" + get(Calendar.ERA) +
"/" + (get(Calendar.MONTH)+1) +
(get(ChineseCalendar.IS_LEAP_MONTH)==1?"(leap)":"") + "/" +
(get(Calendar.IS_LEAP_MONTH)==1?"(leap)":"") + "/" +
get(Calendar.DAY_OF_MONTH);
}
}

View File

@ -3340,7 +3340,7 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
// ChineseDateFormat.Field#ofCalendarField and getCalendarField
int ccalField = ChineseDateFormat.Field.IS_LEAP_MONTH.getCalendarField();
if (ccalField != ChineseCalendar.IS_LEAP_MONTH) {
if (ccalField != Calendar.IS_LEAP_MONTH) {
errln("FAIL: ChineseCalendar field " + ccalField + " is returned for ChineseDateFormat.Field.IS_LEAP_MONTH.getCalendarField()");
} else {
DateFormat.Field cfield = ChineseDateFormat.Field.ofCalendarField(ccalField);
@ -3654,7 +3654,7 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
*/
public void TestOfCalendarField() {
// Tests when if (calendarField == ChineseCalendar.IS_LEAP_MONTH) is false
int[] cases = { ChineseCalendar.IS_LEAP_MONTH - 1};
int[] cases = { Calendar.IS_LEAP_MONTH - 1};
for (int i = 0; i < cases.length; i++) {
try {
Field.ofCalendarField(cases[i]);

View File

@ -1265,7 +1265,10 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
NumberFormat fmt2 = NumberFormat.getInstance(loc2);
NumberFormat fmt3 = NumberFormat.getInstance(loc3);
NumberFormat fmt4 = NumberFormat.getInstance(loc4);
NumberFormat fmt5 = NumberFormat.getInstance(loc3);
fmt5 = NumberFormat.getInstance(loc3);
expect2(fmt1,1234.567,"\u0e51,\u0e52\u0e53\u0e54.\u0e55\u0e56\u0e57");
expect3(fmt2,5678.0,"\u05d4\u05f3\u05ea\u05e8\u05e2\u05f4\u05d7");
expect2(fmt3,1234.567,"\u06f1,\u06f2\u06f3\u06f4.\u06f5\u06f6\u06f7");

View File

@ -136,7 +136,7 @@ public class DebugUtilitiesData extends Object {
com.ibm.icu.util.Calendar.EXTENDED_YEAR, /* 19 */
com.ibm.icu.util.Calendar.JULIAN_DAY, /* 20 */
com.ibm.icu.util.Calendar.MILLISECONDS_IN_DAY, /* 21 */
com.ibm.icu.util.ChineseCalendar.IS_LEAP_MONTH, /* 22 */
com.ibm.icu.util.Calendar.IS_LEAP_MONTH, /* 22 */
},
/* UCalendarMonths, 2 */
{