diff --git a/icu4c/source/i18n/tzfmt.cpp b/icu4c/source/i18n/tzfmt.cpp index 50277c24ef4..a6590786797 100644 --- a/icu4c/source/i18n/tzfmt.cpp +++ b/icu4c/source/i18n/tzfmt.cpp @@ -18,6 +18,7 @@ #include "unicode/uchar.h" #include "unicode/udat.h" #include "unicode/ustring.h" +#include "unicode/utf16.h" #include "tzgnames.h" #include "cmemory.h" #include "cstring.h" @@ -30,6 +31,7 @@ #include "uvector.h" #include "zonemeta.h" #include "tznames_impl.h" // TextTrieMap +#include "patternprops.h" U_NAMESPACE_BEGIN @@ -1862,6 +1864,27 @@ TimeZoneFormat::parseOffsetFieldsWithPattern(const UnicodeString& text, int32_t if (fieldType == GMTOffsetField::TEXT) { const UChar* patStr = field->getPatternText(); len = u_strlen(patStr); + if (i == 0) { + // When TimeZoneFormat parse() is called from SimpleDateFormat, + // leading space characters might be truncated. If the first pattern text + // starts with such character (e.g. Bidi control), then we need to + // skip the leading space charcters. + if (!PatternProps::isWhiteSpace(text.char32At(idx))) { + for (;;) { + UChar32 ch; + int32_t chLen; + U16_GET(patStr, 0, 0, len, ch) + if (PatternProps::isWhiteSpace(ch)) { + chLen = U16_LENGTH(ch); + len -= chLen; + patStr += chLen; + } + else { + break; + } + } + } + } if (text.caseCompare(idx, len, patStr, 0) != 0) { failed = TRUE; break; diff --git a/icu4c/source/test/intltest/tzfmttst.cpp b/icu4c/source/test/intltest/tzfmttst.cpp index d2a841f5433..2cb1eabd06d 100644 --- a/icu4c/source/test/intltest/tzfmttst.cpp +++ b/icu4c/source/test/intltest/tzfmttst.cpp @@ -140,7 +140,8 @@ TimeZoneFormatTest::TestTimeZoneRoundTrip(void) { Locale("en"), Locale("en_CA"), Locale("fr"), - Locale("zh_Hant") + Locale("zh_Hant"), + Locale("fa") }; const Locale *LOCALES; @@ -162,9 +163,6 @@ TimeZoneFormatTest::TestTimeZoneRoundTrip(void) { if (uprv_strcmp(LOCALES[locidx].getLanguage(),"ccp")==0 && logKnownIssue("13366", "Skip handling ccp until TimeZone offset roundtrip is fixed")) { continue; } - if (uprv_strcmp(LOCALES[locidx].getLanguage(),"fa")==0 && logKnownIssue("13374", "Skip handling fa until TimeZone offset roundtrip is fixed")) { - continue; - } UnicodeString localGMTString; SimpleDateFormat gmtFmt(UnicodeString("ZZZZ"), LOCALES[locidx], status); if (U_FAILURE(status)) { diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TimeZoneFormatTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TimeZoneFormatTest.java index ea907cee4ce..e3719cfd971 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TimeZoneFormatTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TimeZoneFormatTest.java @@ -128,7 +128,7 @@ public class TimeZoneFormatTest extends TestFmwk { if (TEST_ALL || TestFmwk.getExhaustiveness() > 5) { LOCALES = ULocale.getAvailableLocales(); } else { - LOCALES = new ULocale[] {new ULocale("en"), new ULocale("en_CA"), new ULocale("fr"), new ULocale("zh_Hant")}; + LOCALES = new ULocale[] {new ULocale("en"), new ULocale("en_CA"), new ULocale("fr"), new ULocale("zh_Hant"), new ULocale("fa")}; } String[] tzids;