Skip to content

Commit

Permalink
ICU-22041 Fix "Africa/Casablanca" show strange LONG displayName
Browse files Browse the repository at this point in the history
See #2096
  • Loading branch information
FrankYFTang authored and Squash Bot committed May 25, 2022
1 parent f6300c9 commit 5b86e0b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
3 changes: 1 addition & 2 deletions icu4c/source/i18n/olsontz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,7 @@ void OlsonTimeZone::setRawOffset(int32_t /*offsetMillis*/) {
int32_t OlsonTimeZone::getRawOffset() const {
UErrorCode ec = U_ZERO_ERROR;
int32_t raw, dst;
getOffset((double) uprv_getUTCtime() * U_MILLIS_PER_SECOND,
FALSE, raw, dst, ec);
getOffset((double) uprv_getUTCtime(), FALSE, raw, dst, ec);
return raw;
}

Expand Down
5 changes: 2 additions & 3 deletions icu4c/source/i18n/rbtz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,7 @@ RuleBasedTimeZone::getRawOffset(void) const {
// as of current time.
UErrorCode status = U_ZERO_ERROR;
int32_t raw, dst;
getOffset(uprv_getUTCtime() * U_MILLIS_PER_SECOND,
FALSE, raw, dst, status);
getOffset(uprv_getUTCtime(), FALSE, raw, dst, status);
return raw;
}

Expand All @@ -490,7 +489,7 @@ RuleBasedTimeZone::useDaylightTime(void) const {
// daylight saving time is used as of now or
// after the next transition.
UErrorCode status = U_ZERO_ERROR;
UDate now = uprv_getUTCtime() * U_MILLIS_PER_SECOND;
UDate now = uprv_getUTCtime();
int32_t raw, dst;
getOffset(now, FALSE, raw, dst, status);
if (dst != 0) {
Expand Down
39 changes: 39 additions & 0 deletions icu4c/source/test/intltest/tztest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ void TimeZoneTest::runIndexedTest( int32_t index, UBool exec, const char* &name,
TESTCASE_AUTO(TestGetGMT);
TESTCASE_AUTO(TestGetWindowsID);
TESTCASE_AUTO(TestGetIDForWindowsID);
TESTCASE_AUTO(TestCasablancaNameAndOffset22041);
TESTCASE_AUTO(TestRawOffsetAndOffsetConsistency22041);
TESTCASE_AUTO_END;
}

Expand Down Expand Up @@ -2544,4 +2546,41 @@ void TimeZoneTest::TestGetIDForWindowsID(void) {
}
}

void TimeZoneTest::TestCasablancaNameAndOffset22041(void) {
std::unique_ptr<TimeZone> zone(TimeZone::createTimeZone("Africa/Casablanca"));
UnicodeString standardName, summerName;
zone->getDisplayName(false, TimeZone::LONG, Locale::getEnglish(), standardName);
zone->getDisplayName(true, TimeZone::LONG, Locale::getEnglish(), summerName);
int32_t raw, dst;
UErrorCode status = U_ZERO_ERROR;
zone->getOffset(Calendar::getNow(), false, raw, dst, status);
assertEquals(u"TimeZone name for Africa/Casablanca should not contain '+02' since it is located in UTC, but got "
+ standardName, -1, standardName.indexOf("+02"));
assertEquals(u"TimeZone name for Africa/Casablanca should not contain '+02' since it is located in UTC, but got "
+ summerName, -1, summerName.indexOf("+02"));
assertEquals("getRawOffset() and the raw from getOffset(now, false, raw, dst, status) should not be different but got",
zone->getRawOffset(), raw);
}

void TimeZoneTest::TestRawOffsetAndOffsetConsistency22041(void) {
UErrorCode status = U_ZERO_ERROR;
LocalPointer<StringEnumeration> s(TimeZone::createEnumeration(status));
if (U_FAILURE(status)) {
dataerrln("Unable to create TimeZone enumeration");
return;
}
const char* tz;
UDate now = Calendar::getNow();
while ((tz = s->next(nullptr, status)) != nullptr && U_SUCCESS(status)) {
std::unique_ptr<TimeZone> zone(TimeZone::createTimeZone(tz));
int32_t raw, dst;
zone->getOffset(now, false, raw, dst, status);
if (U_FAILURE(status)) {
errln("TimeZone '%s' getOffset() return error", tz);
}
assertEquals(u"TimeZone '" + UnicodeString(tz) +
u"' getRawOffset() and the raw from getOffset(now, false, raw, dst, status) should not be different but got",
zone->getRawOffset(), raw);
}
}
#endif /* #if !UCONFIG_NO_FORMATTING */
2 changes: 2 additions & 0 deletions icu4c/source/test/intltest/tztest.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class TimeZoneTest: public CalendarTimeZoneTest {

void TestGetWindowsID(void);
void TestGetIDForWindowsID(void);
void TestCasablancaNameAndOffset22041(void);
void TestRawOffsetAndOffsetConsistency22041(void);

static const UDate INTERVAL;

Expand Down

0 comments on commit 5b86e0b

Please sign in to comment.