From 252149b02a539b4dd5fb63f639d7034793d739fc Mon Sep 17 00:00:00 2001 From: Jason Spieth Date: Mon, 27 Jul 2009 17:09:00 +0000 Subject: [PATCH] ICU-6033 IS_LEAP_MONTH moved from ChineseCalendar to Calendar X-SVN-Rev: 26443 --- .../core/src/com/ibm/icu/util/Calendar.java | 17 +++++++++-- .../src/com/ibm/icu/util/ChineseCalendar.java | 20 ++----------- .../dev/test/calendar/CalendarRegression.java | 3 +- .../icu/dev/test/calendar/CalendarTest.java | 4 +-- .../icu/dev/test/calendar/ChineseTest.java | 28 +++++++++---------- .../dev/test/calendar/ChineseTestCase.java | 6 ++-- .../icu/dev/test/format/DateFormatTest.java | 4 +-- .../icu/dev/test/format/NumberFormatTest.java | 5 +++- .../icu/dev/test/util/DebugUtilitiesData.java | 2 +- 9 files changed, 44 insertions(+), 45 deletions(-) diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java b/icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java index 6511c80110..bcf8b06cdd 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java @@ -939,12 +939,19 @@ public abstract class Calendar implements Serializable, Cloneable, ComparableThis class defines one addition field beyond those defined by - * Calendar: The IS_LEAP_MONTH field takes the - * value of 0 for normal months, or 1 for leap months. - * *

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 diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/CalendarRegression.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/CalendarRegression.java index 75f7fc1936..ff03feb65f 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/CalendarRegression.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/CalendarRegression.java @@ -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 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); diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/ChineseTestCase.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/ChineseTestCase.java index 924b6aa631..f65a307b48 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/ChineseTestCase.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/ChineseTestCase.java @@ -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); } } diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DateFormatTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DateFormatTest.java index 982d0784b9..5db272e9d8 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DateFormatTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DateFormatTest.java @@ -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]); diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTest.java index ccb0f848ca..715eb9dfb6 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTest.java @@ -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"); diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/DebugUtilitiesData.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/DebugUtilitiesData.java index 56a8a1f2d2..377870f9a1 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/DebugUtilitiesData.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/DebugUtilitiesData.java @@ -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 */ {