diff --git a/icu4c/source/i18n/dtitvinf.cpp b/icu4c/source/i18n/dtitvinf.cpp index 51f2d00fe64..bd6d3f9f47b 100644 --- a/icu4c/source/i18n/dtitvinf.cpp +++ b/icu4c/source/i18n/dtitvinf.cpp @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright (C) 2008-2014, International Business Machines Corporation and +* Copyright (C) 2008-2015, International Business Machines Corporation and * others. All Rights Reserved. ******************************************************************************* * @@ -223,7 +223,7 @@ DateIntervalInfo::initializeData(const Locale& locale, UErrorCode& err) char parentLocale[ULOC_FULLNAME_CAPACITY]; uprv_strcpy(parentLocale, locName); UErrorCode status = U_ZERO_ERROR; - Hashtable skeletonSet(FALSE, status); + Hashtable skeletonKeyPairs(FALSE, status); if ( U_FAILURE(status) ) { return; } @@ -277,10 +277,6 @@ DateIntervalInfo::initializeData(const Locale& locale, UErrorCode& err) continue; } UnicodeString skeletonUniStr(skeleton, -1, US_INV); - if ( skeletonSet.geti(skeletonUniStr) == 1 ) { - continue; - } - skeletonSet.puti(skeletonUniStr, 1, status); if ( uprv_strcmp(skeleton, gFallbackPatternTag) == 0 ) { continue; // fallback } @@ -304,6 +300,12 @@ DateIntervalInfo::initializeData(const Locale& locale, UErrorCode& err) if ( U_FAILURE(status) ) { break; } + UnicodeString keyUniStr(key, -1, US_INV); + UnicodeString skeletonKeyPair(skeletonUniStr + keyUniStr); + if ( skeletonKeyPairs.geti(skeletonKeyPair) == 1 ) { + continue; + } + skeletonKeyPairs.puti(skeletonKeyPair, 1, status); UCalendarDateFields calendarField = UCAL_FIELD_COUNT; if ( !uprv_strcmp(key, "y") ) { diff --git a/icu4c/source/test/intltest/dtifmtts.cpp b/icu4c/source/test/intltest/dtifmtts.cpp index a9dc8b5caaf..31c4b712388 100644 --- a/icu4c/source/test/intltest/dtifmtts.cpp +++ b/icu4c/source/test/intltest/dtifmtts.cpp @@ -49,6 +49,7 @@ void DateIntervalFormatTest::runIndexedTest( int32_t index, UBool exec, const ch TESTCASE(3, testSetIntervalPatternNoSideEffect); TESTCASE(4, testYearFormats); TESTCASE(5, testStress); + TESTCASE(6, testTicket11583_2); default: name = ""; break; } } @@ -1509,4 +1510,24 @@ void DateIntervalFormatTest::stress(const char** data, int32_t data_length, } } +void DateIntervalFormatTest::testTicket11583_2() { + UErrorCode status = U_ZERO_ERROR; + LocalPointer fmt( + DateIntervalFormat::createInstance("yMMM", "es-US", status)); + if (!assertSuccess("Error create format object", status)) { + return; + } + DateInterval interval((UDate) 1232364615000.0, (UDate) 1328787015000.0); + UnicodeString appendTo; + FieldPosition fpos(FieldPosition::DONT_CARE); + UnicodeString expected("ene. de 2009 \u2013 feb. de 2012"); + assertEquals( + "", + expected.unescape(), + fmt->format(&interval, appendTo, fpos, status)); + if (!assertSuccess("Error formatting", status)) { + return; + } +} + #endif /* #if !UCONFIG_NO_FORMATTING */ diff --git a/icu4c/source/test/intltest/dtifmtts.h b/icu4c/source/test/intltest/dtifmtts.h index 8e6faf0c597..3d50f72e6a3 100644 --- a/icu4c/source/test/intltest/dtifmtts.h +++ b/icu4c/source/test/intltest/dtifmtts.h @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 2008-2013 International Business Machines Corporation and + * Copyright (c) 2008-2015 International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ @@ -52,6 +52,8 @@ public: */ void testStress(); + void testTicket11583_2(); + private: /** * Test formatting against expected result