]> granicus.if.org Git - icu/commitdiff
ICU-8589 Corrected the condition for using country display name in a time zone partia...
authorYoshito Umaoka <y.umaoka@gmail.com>
Thu, 26 May 2011 20:56:15 +0000 (20:56 +0000)
committerYoshito Umaoka <y.umaoka@gmail.com>
Thu, 26 May 2011 20:56:15 +0000 (20:56 +0000)
X-SVN-Rev: 30149

icu4c/source/i18n/tzgnames.cpp
icu4c/source/test/intltest/dtfmttst.cpp

index 745c729aca142b36582d35d3e68fb90a66c54c52..3abcc36091b8dc20a3840f920047559ca4c7fdc9 100644 (file)
@@ -740,13 +740,22 @@ TimeZoneGenericNames::getPartialLocationName(const UnicodeString& tzCanonicalID,
 
     UnicodeString location;
     UnicodeString usCountryCode;
-    ZoneMeta::getSingleCountry(tzCanonicalID, usCountryCode);
+    ZoneMeta::getCanonicalCountry(tzCanonicalID, usCountryCode);
     if (!usCountryCode.isEmpty()) {
         char countryCode[ULOC_COUNTRY_CAPACITY];
         U_ASSERT(usCountryCode.length() < ULOC_COUNTRY_CAPACITY);
         int32_t ccLen = usCountryCode.extract(0, usCountryCode.length(), countryCode, sizeof(countryCode), US_INV);
         countryCode[ccLen] = 0;
-        fLocaleDisplayNames->regionDisplayName(countryCode, location);
+
+        UnicodeString regionalGolden;
+        fTimeZoneNames->getReferenceZoneID(mzID, countryCode, regionalGolden);
+        if (tzCanonicalID == regionalGolden) {
+            // Use country name
+            fLocaleDisplayNames->regionDisplayName(countryCode, location);
+        } else {
+            // Otherwise, use exemplar city name
+            fTimeZoneNames->getExemplarLocationName(tzCanonicalID, location);
+        }
     } else {
         fTimeZoneNames->getExemplarLocationName(tzCanonicalID, location);
         if (location.isEmpty()) {
index 7a373532af7a9949be54b68bab63aae5c82fe431..7f6078874aa1fc089614859920c06274dd5fa954 100644 (file)
@@ -3049,12 +3049,21 @@ void DateFormatTest::TestTimeZoneDisplayName()
         { "ti", "Asia/Calcutta", "2004-07-15T00:00:00Z", "zzzz", "GMT+05:30", "+5:30" },
         { "ti", "Asia/Calcutta", "2004-07-15T00:00:00Z", "v", "(IN)", "Alna/Calcutta" },
         { "ti", "Asia/Calcutta", "2004-07-15T00:00:00Z", "vvvv", "(IN)", "Asia/Calcutta" },
+
+        // Ticket#8589 Partial location name to use country name if the zone is the golden
+        // zone for the time zone's country.
+        { "en_MX", "America/Chicago", "1995-07-15T00:00:00Z", "vvvv", "Central Time (United States)", "America/Chicago"},
+
         { NULL, NULL, NULL, NULL, NULL, NULL },
     };
 
     UErrorCode status = U_ZERO_ERROR;
     Calendar *cal = GregorianCalendar::createInstance(status);
     if (failure(status, "GregorianCalendar::createInstance", TRUE)) return;
+    SimpleDateFormat testfmt(UnicodeString("yyyy-MM-dd'T'HH:mm:ss'Z'"), status);
+    if (failure(status, "SimpleDateFormat constructor", TRUE)) return;
+    testfmt.setTimeZone(*TimeZone::getGMT());
+
     for (int i = 0; fallbackTests[i][0]; i++) {
         const char **testLine = fallbackTests[i];
         UnicodeString info[5];
@@ -3066,10 +3075,10 @@ void DateFormatTest::TestTimeZoneDisplayName()
 
         TimeZone *tz = TimeZone::createTimeZone(info[1]);
 
-        if (strcmp(testLine[2], "2004-07-15T00:00:00Z") == 0) {
-            cal->set(2004,6,15,0,0,0);
-        } else {
-            cal->set(2004,0,15,0,0,0);
+        UDate d = testfmt.parse(testLine[2], status);
+        cal->setTime(d, status);
+        if (U_FAILURE(status)) {
+            errln(UnicodeString("Failed to set date: ") + testLine[2]);
         }
 
         SimpleDateFormat fmt(info[3], Locale(testLine[0]),status);