if (U_SUCCESS(status)) {
while ((mzID = mzIDs->snext(status)) && U_SUCCESS(status)) {
const TZDBNames *names = TZDBTimeZoneNames::getMetaZoneNames(*mzID, status);
+ if (U_FAILURE(status)) {
+ break;
+ }
if (names == NULL) {
continue;
}
UErrorCode status = U_ZERO_ERROR;
const TZDBNames *tzdbNames = TZDBTimeZoneNames::getMetaZoneNames(mzID, status);
if (U_SUCCESS(status)) {
- const UChar *s = tzdbNames->getName(type);
- if (s != NULL) {
- name.setTo(TRUE, s, -1);
+ if (tzdbNames != NULL) {
+ const UChar *s = tzdbNames->getName(type);
+ if (s != NULL) {
+ name.setTo(TRUE, s, -1);
+ }
}
}
TimeZoneNames::MatchInfoCollection* find(const UnicodeString& text, int32_t start, uint32_t types, UErrorCode& status) const;
+ // When TZDBNames for the metazone is not available, this method returns NULL,
+ // but does NOT set U_MISSING_RESOURCE_ERROR to status.
static const TZDBNames* getMetaZoneNames(const UnicodeString& mzId, UErrorCode& status);
private:
TESTCASE(4, TestFormat);
TESTCASE(5, TestFormatTZDBNames);
TESTCASE(6, TestFormatCustomZone);
- default: name = ""; break;
+ TESTCASE(7, TestFormatTZDBNamesAllZoneCoverage);
+ default: name = ""; break;
}
}
}
}
+void
+TimeZoneFormatTest::TestFormatTZDBNamesAllZoneCoverage(void) {
+ UErrorCode status = U_ZERO_ERROR;
+ LocalPointer<StringEnumeration> tzids(TimeZone::createEnumeration());
+ const UnicodeString *tzid;
+ LocalPointer<TimeZoneNames> tzdbNames(TimeZoneNames::createTZDBInstance(Locale("en"), status));
+ UDate now = Calendar::getNow();
+ UnicodeString mzId;
+ UnicodeString name;
+ while ((tzid = tzids->snext(status))) {
+ logln("Zone: " + *tzid);
+ LocalPointer<TimeZone> tz(TimeZone::createTimeZone(*tzid));
+ tzdbNames->getMetaZoneID(*tzid, now, mzId);
+ if (mzId.isBogus()) {
+ logln((UnicodeString)"Meta zone: <not available>");
+ } else {
+ logln((UnicodeString)"Meta zone: " + mzId);
+ }
+
+ // mzID could be bogus here
+ tzdbNames->getMetaZoneDisplayName(mzId, UTZNM_SHORT_STANDARD, name);
+ // name could be bogus here
+ if (name.isBogus()) {
+ logln((UnicodeString)"Meta zone short standard name: <not available>");
+ }
+ else {
+ logln((UnicodeString)"Meta zone short standard name: " + name);
+ }
+
+ tzdbNames->getMetaZoneDisplayName(mzId, UTZNM_SHORT_DAYLIGHT, name);
+ // name could be bogus here
+ if (name.isBogus()) {
+ logln((UnicodeString)"Meta zone short daylight name: <not available>");
+ }
+ else {
+ logln((UnicodeString)"Meta zone short daylight name: " + name);
+ }
+ }
+}
#endif /* #if !UCONFIG_NO_FORMATTING */