/*********************************************************************
- * Copyright (C) 2000-2011, International Business Machines Corporation and
+ * Copyright (C) 2000-2012, International Business Machines Corporation and
* others. All Rights Reserved.
*********************************************************************
*/
import java.io.InvalidObjectException;
import java.text.FieldPosition;
-import java.text.ParsePosition;
import java.util.Locale;
-import com.ibm.icu.impl.PatternProps;
import com.ibm.icu.util.Calendar;
import com.ibm.icu.util.ChineseCalendar;
import com.ibm.icu.util.TimeZone;
* @see com.ibm.icu.util.ChineseCalendar
* @see ChineseDateFormatSymbols
* @author Alan Liu
- * @stable ICU 2.0
+ * @deprecated ICU 50 Use SimpleDateFormat instead.
*/
public class ChineseDateFormat extends SimpleDateFormat {
// Generated by serialver from JDK 1.4.1_01
* Construct a ChineseDateFormat from a date format pattern and locale
* @param pattern the pattern
* @param locale the locale
- * @stable ICU 2.0
+ * @deprecated ICU 50
*/
public ChineseDateFormat(String pattern, Locale locale) {
this(pattern, ULocale.forLocale(locale));
* Construct a ChineseDateFormat from a date format pattern and locale
* @param pattern the pattern
* @param locale the locale
- * @stable ICU 3.2
+ * @deprecated ICU 50
*/
public ChineseDateFormat(String pattern, ULocale locale) {
this(pattern, null, locale);
* string by separating them with a semi-colon. For example, the override string "m=thai;y=deva" would format using
* Thai digits for the month and Devanagari digits for the year.
* @param locale the locale
- * @stable ICU 4.2
+ * @deprecated ICU 50
*/
public ChineseDateFormat(String pattern, String override, ULocale locale) {
super(pattern, new ChineseDateFormatSymbols(locale),
*/
protected void subFormat(StringBuffer buf,
char ch, int count, int beginOffset,
+ int fieldNum, DisplayContext capitalizationContext,
FieldPosition pos,
Calendar cal) {
- switch (ch) {
- case 'G': // 'G' - ERA
- zeroPaddingNumber(numberFormat,buf, cal.get(Calendar.ERA), 1, 9);
- break;
- case 'l': // 'l' - IS_LEAP_MONTH
- buf.append(((ChineseDateFormatSymbols) getSymbols()).
- getLeapMonth(cal.get(ChineseCalendar.IS_LEAP_MONTH)));
- break;
- default:
- super.subFormat(buf, ch, count, beginOffset, pos, cal);
- break;
- }
+ // Logic to handle 'G' for chinese calendar is moved into SimpleDateFormat,
+ // and obsolete pattern char 'l' is now ignored in SimpleDateFormat, so we
+ // just use its implementation
+ super.subFormat(buf, ch, count, beginOffset, fieldNum, capitalizationContext, pos, cal);
+ // The following is no longer an issue for this subclass...
// TODO: add code to set FieldPosition for 'G' and 'l' fields. This
// is a DESIGN FLAW -- subclasses shouldn't have to duplicate the
// code that handles this at the end of SimpleDateFormat.subFormat.
/**
* {@inheritDoc}
*
- * @stable ICU 2.0
+ * @deprecated ICU 50
*/
protected int subParse(String text, int start, char ch, int count, boolean obeyCount, boolean allowNegative,
boolean[] ambiguousYear, Calendar cal) {
- if (ch != 'G' && ch != 'l' && ch != 'y') {
- return super.subParse(text, start, ch, count, obeyCount, allowNegative, ambiguousYear, cal);
- }
-
- // Skip whitespace
- start = PatternProps.skipWhiteSpace(text, start);
-
- ParsePosition pos = new ParsePosition(start);
-
- switch (ch) {
- case 'G': // 'G' - ERA
- case 'y': // 'y' - YEAR, but without the 2-digit Y2K adjustment
- {
- Number number = null;
- if (obeyCount) {
- if ((start + count) > text.length()) {
- return -start;
- }
- number = numberFormat.parse(text.substring(0, start + count), pos);
- } else {
- number = numberFormat.parse(text, pos);
- }
- if (number == null) {
- return -start;
- }
- int value = number.intValue();
- cal.set(ch == 'G' ? Calendar.ERA : Calendar.YEAR, value);
- return pos.getIndex();
- }
- case 'l': // 'l' - IS_LEAP_MONTH
- {
- ChineseDateFormatSymbols symbols = (ChineseDateFormatSymbols) getSymbols();
- int result = matchString(text, start, ChineseCalendar.IS_LEAP_MONTH, symbols.isLeapMonth, cal);
- // Treat the absence of any matching string as setting
- // IS_LEAP_MONTH to false.
- if (result < 0) {
- cal.set(ChineseCalendar.IS_LEAP_MONTH, 0);
- result = start;
- }
- return result;
- }
- ///CLOVER:OFF
- default:
- return 0; // This can never happen
- ///CLOVER:ON
- }
+ // Logic to handle numeric 'G' eras for chinese calendar, and to skip special 2-digit year
+ // handling for chinese calendar, is moved into SimpleDateFormat, so delete here.
+ // Obsolete pattern char 'l' is now ignored for parsing in SimpleDateFormat, no handling
+ // needed here.
+ // So just use SimpleDateFormat implementation for this.
+ // just use its implementation
+ return super.subParse(text, start, ch, count, obeyCount, allowNegative, ambiguousYear, cal);
}
/**
* {@inheritDoc}
*
- * @stable ICU 3.8
+ * @deprecated ICU 50
*/
protected DateFormat.Field patternCharToDateFormatField(char ch) {
- if (ch == 'l') {
- return ChineseDateFormat.Field.IS_LEAP_MONTH;
- }
+ // no longer any field corresponding to pattern char 'l'
return super.patternCharToDateFormatField(ch);
}
* There is no public constructor to this class, the only instances are the
* constants defined here.
* <p>
- * @stable ICU 3.8
+ * @deprecated ICU 50
*/
public static class Field extends DateFormat.Field {
/**
* Constant identifying the leap month marker.
- * @stable ICU 3.8
+ * @deprecated ICU 50 This field is only used by the deprecated ChineseDateFormat class.
*/
public static final Field IS_LEAP_MONTH = new Field("is leap month", ChineseCalendar.IS_LEAP_MONTH);
* @param name Name of the attribute
* @param calendarField <code>Calendar</code> field constant
*
- * @stable ICU 3.8
+ * @deprecated ICU 50
*/
protected Field(String name, int calendarField) {
super(name, calendarField);
* @throws IllegalArgumentException if <code>calendarField</code> is not
* a valid <code>Calendar</code> field constant.
*
- * @stable ICU 3.8
+ * @deprecated ICU 50
*/
public static DateFormat.Field ofCalendarField(int calendarField) {
+ // Should we remove the following, since there is no longer a specific
+ // date format field for leap month (since 'l' pattern char is obsolete)?
if (calendarField == ChineseCalendar.IS_LEAP_MONTH) {
return IS_LEAP_MONTH;
}
/**
* {@inheritDoc}
*
- * @stable ICU 3.8
+ * @deprecated ICU 50
*/
///CLOVER:OFF
protected Object readResolve() throws InvalidObjectException {