ICU-4904 calling toLocalizedPattern on a ChineseDateFormat that uses its standard patterns throws an Exception since 'l' is a pattern char but not one of the standard DateFormat pattern chars

X-SVN-Rev: 18765
This commit is contained in:
Doug Felt 2005-11-07 21:39:39 +00:00
parent aa568d1178
commit fcacfabdcb
2 changed files with 24 additions and 5 deletions

View file

@ -1833,6 +1833,25 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
}
}
public void TestChineseDateFormatLocalizedPatternChars() {
// jb 4904
// make sure we can display localized versions of the chars used in the default
// chinese date format patterns
Calendar chineseCalendar = new ChineseCalendar();
chineseCalendar.setTimeInMillis((new Date()).getTime());
SimpleDateFormat longChineseDateFormat =
(SimpleDateFormat)chineseCalendar.getDateTimeFormat(DateFormat.LONG, DateFormat.LONG, Locale.CHINA );
DateFormatSymbols dfs = new ChineseDateFormatSymbols( chineseCalendar, Locale.CHINA );
longChineseDateFormat.setDateFormatSymbols( dfs );
// This next line throws the exception
try {
String longFormatPattern = longChineseDateFormat.toLocalizedPattern();
}
catch (Exception e) {
errln("could not localized pattern: " + e.getMessage());
}
}
public void TestCoverage() {
Date now = new Date();
Calendar cal = new GregorianCalendar();

View file

@ -1748,11 +1748,11 @@ public class SimpleDateFormat extends DateFormat {
inQuote = true;
else if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
int ci = from.indexOf(c);
if (ci == -1)
throw new IllegalArgumentException("Illegal pattern " +
" character '" +
c + "'");
c = to.charAt(ci);
if (ci != -1) {
c = to.charAt(ci);
}
// do not worry on translatepattern if the character is not listed
// we do the validity check elsewhere
}
}
result.append(c);