From cb472ddf5209c0a5ed1aea602d8a64831ff52229 Mon Sep 17 00:00:00 2001 From: Peter Edberg Date: Thu, 19 Jan 2012 04:56:22 +0000 Subject: [PATCH] ICU-8959 If pattern char is 'U' but year has no cyclic name data, format as number (C) X-SVN-Rev: 31224 --- icu4c/source/i18n/smpdtfmt.cpp | 15 +++++++++------ icu4c/source/test/intltest/dtfmttst.cpp | 7 ++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/icu4c/source/i18n/smpdtfmt.cpp b/icu4c/source/i18n/smpdtfmt.cpp index 38eb2611402..3e342edde0e 100644 --- a/icu4c/source/i18n/smpdtfmt.cpp +++ b/icu4c/source/i18n/smpdtfmt.cpp @@ -1591,7 +1591,15 @@ SimpleDateFormat::subFormat(UnicodeString &appendTo, } break; - // OLD: for "yyyy", write out the whole year; for "yy", write out the last 2 digits + case UDAT_YEAR_NAME_FIELD: + if (fSymbols->fShortYearNames != NULL && value <= fSymbols->fShortYearNamesCount) { + // the Calendar YEAR field runs 1 through 60 for cyclic years + _appendSymbol(appendTo, value - 1, fSymbols->fShortYearNames, fSymbols->fShortYearNamesCount); + break; + } + // else fall through to numeric year handling, do not break here + + // OLD: for "yyyy", write out the whole year; for "yy", write out the last 2 digits // NEW: UTS#35: //Year y yy yyy yyyy yyyyy //AD 1 1 01 001 0001 00001 @@ -1607,11 +1615,6 @@ SimpleDateFormat::subFormat(UnicodeString &appendTo, zeroPaddingNumber(currentNumberFormat, appendTo, value, count, maxIntCount); break; - case UDAT_YEAR_NAME_FIELD: - // the Calendar YEAR field runs 1 through 60 for cyclic years - _appendSymbol(appendTo, value - 1, fSymbols->fShortYearNames, fSymbols->fShortYearNamesCount); - break; - // for "MMMM"/"LLLL", write out the whole month name, for "MMM"/"LLL", write out the month // abbreviation, for "M"/"L" or "MM"/"LL", write out the month as a number with the // appropriate number of digits diff --git a/icu4c/source/test/intltest/dtfmttst.cpp b/icu4c/source/test/intltest/dtfmttst.cpp index ba6be163570..86c9046966a 100644 --- a/icu4c/source/test/intltest/dtfmttst.cpp +++ b/icu4c/source/test/intltest/dtfmttst.cpp @@ -398,11 +398,11 @@ void DateFormatTest::TestFieldPosition() { "mercredi", "", "", "", "", "", "", "", "heure avanc\\u00e9e du Pacifique", "", "", "", "", "", "", "", "", "", "", "", "","", "AD", "1997", "8", "13", "14", "14", "34", "12", "5", - "Wed", "225", "2", "33", "3", "PM", "2", "2", "PDT", "1997", "4", "1997", "2450674", "52452513", "-0700", "PT", "4", "8", "3", "3","PDT","", + "Wed", "225", "2", "33", "3", "PM", "2", "2", "PDT", "1997", "4", "1997", "2450674", "52452513", "-0700", "PT", "4", "8", "3", "3","PDT","1997", "Anno Domini", "1997", "August", "0013", "0014", "0014", "0034", "0012", "5130", "Wednesday", "0225", "0002", "0033", "0003", "PM", "0002", "0002", "Pacific Daylight Time", "1997", "Wednesday", "1997", "2450674", "52452513", "GMT-07:00", - "Pacific Time", "Wednesday", "August", "3rd quarter", "3rd quarter", "United States Time (Los Angeles)","" + "Pacific Time", "Wednesday", "August", "3rd quarter", "3rd quarter", "United States Time (Los Angeles)","1997" }; const int32_t EXPECTED_LENGTH = sizeof(EXPECTED)/sizeof(EXPECTED[0]); @@ -3736,6 +3736,7 @@ void DateFormatTest::TestMonthPatterns() { "root@calendar=chinese", -2, { UnicodeString("78x29-4-2"), UnicodeString("78x29-4bis-2"), UnicodeString("78x29-5-2") } }, { "root@calendar=chinese", -3, { UnicodeString("ren-chen-4-2"), UnicodeString("ren-chen-4bis-2"), UnicodeString("ren-chen-5-2") } }, { "root@calendar=chinese", -4, { UnicodeString("ren-chen 4 2"), UnicodeString("ren-chen 4bis 2"), UnicodeString("ren-chen 5 2") } }, + { "en@calendar=gregorian", -3, { UnicodeString("2012-4-22"), UnicodeString("2012-5-22"), UnicodeString("2012-6-20") } }, { "en@calendar=chinese", DateFormat::kLong, { UnicodeString("ren-chen 4 2"), UnicodeString("ren-chen 4bis 2"), UnicodeString("ren-chen 5 2") } }, { "en@calendar=chinese", DateFormat::kShort, { UnicodeString("29-4-2"), UnicodeString("29-4bis-2"), UnicodeString("29-5-2") } }, { "zh@calendar=chinese", DateFormat::kLong, { CharsToUnicodeString("\\u58EC\\u8FB0\\u5E74\\u56DB\\u6708\\u4E8C\\u65E5"), @@ -3792,7 +3793,7 @@ void DateFormatTest::TestMonthPatterns() if ( result.compare(itemPtr->dateString[idate]) != 0 ) { errln( UnicodeString("FAIL: Chinese calendar format for locale ") + UnicodeString(itemPtr->locale) + ", style " + itemPtr->style + ", expected \"" + itemPtr->dateString[idate] + "\", got \"" + result + "\""); - } else { + } else if (uprv_strstr(itemPtr->locale, "calendar=chinese") != NULL) { // formatted OK, try parse ParsePosition ppos(0); // ensure we are really parsing the fields we should be -- 2.40.0