+void
+TimeZoneFormatTest::TestFormatCustomZone(void) {
+ struct {
+ const char* id;
+ int32_t offset;
+ const char* expected;
+ } TESTDATA[] = {
+ { "abc", 3600000, "GMT+01:00" }, // unknown ID
+ { "$abc", -3600000, "GMT-01:00" }, // unknown, with ASCII variant char '$'
+ { "\\u00c1\\u00df\\u00c7", 5400000, "GMT+01:30"}, // unknown, with non-ASCII chars
+ { 0, 0, 0 }
+ };
+
+ UDate now = Calendar::getNow();
+
+ for (int32_t i = 0; ; i++) {
+ const char *id = TESTDATA[i].id;
+ if (id == 0) {
+ break;
+ }
+ UnicodeString tzid = UnicodeString(id, -1, US_INV).unescape();
+ SimpleTimeZone tz(TESTDATA[i].offset, tzid);
+
+ UErrorCode status = U_ZERO_ERROR;
+ LocalPointer<TimeZoneFormat> tzfmt(TimeZoneFormat::createInstance(Locale("en"), status));
+ if (tzfmt.isNull()) {
+ dataerrln("FAIL: TimeZoneFormat::createInstance failed for en");
+ return;
+ }
+ UnicodeString tzstr;
+ UnicodeString expected = UnicodeString(TESTDATA[i].expected, -1, US_INV).unescape();
+
+ tzfmt->format(UTZFMT_STYLE_SPECIFIC_LONG, tz, now, tzstr, NULL);
+ assertEquals(UnicodeString("Format result for ") + tzid, expected, tzstr);
+ }
+}
+
+void
+TimeZoneFormatTest::TestFormatTZDBNamesAllZoneCoverage(void) {
+ UErrorCode status = U_ZERO_ERROR;
+ LocalPointer<StringEnumeration> tzids(TimeZone::createEnumeration());
+ if (tzids.getAlias() == nullptr) {
+ dataerrln("%s %d tzids is null", __FILE__, __LINE__);
+ return;
+ }
+ 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);
+ }
+ }
+}