blob: faaa3a360c9d3a3c450b6f01d955badaae972ba3 [file] [log] [blame]
Frank Tang12de9662022-05-26 15:08:08 -07001diff --git a/source/i18n/olsontz.cpp b/source/i18n/olsontz.cpp
2index cae471a5..0f06db5c 100644
3--- a/source/i18n/olsontz.cpp
4+++ b/source/i18n/olsontz.cpp
5@@ -430,8 +430,7 @@ void OlsonTimeZone::setRawOffset(int32_t /*offsetMillis*/) {
6 int32_t OlsonTimeZone::getRawOffset() const {
7 UErrorCode ec = U_ZERO_ERROR;
8 int32_t raw, dst;
9- getOffset((double) uprv_getUTCtime() * U_MILLIS_PER_SECOND,
10- FALSE, raw, dst, ec);
11+ getOffset(uprv_getUTCtime(), FALSE, raw, dst, ec);
12 return raw;
13 }
14
15diff --git a/source/i18n/rbtz.cpp b/source/i18n/rbtz.cpp
16index 495d8310..7eba471a 100644
17--- a/source/i18n/rbtz.cpp
18+++ b/source/i18n/rbtz.cpp
19@@ -479,8 +479,7 @@ RuleBasedTimeZone::getRawOffset(void) const {
20 // as of current time.
21 UErrorCode status = U_ZERO_ERROR;
22 int32_t raw, dst;
23- getOffset(uprv_getUTCtime() * U_MILLIS_PER_SECOND,
24- FALSE, raw, dst, status);
25+ getOffset(uprv_getUTCtime(), FALSE, raw, dst, status);
26 return raw;
27 }
28
29@@ -490,7 +489,7 @@ RuleBasedTimeZone::useDaylightTime(void) const {
30 // daylight saving time is used as of now or
31 // after the next transition.
32 UErrorCode status = U_ZERO_ERROR;
33- UDate now = uprv_getUTCtime() * U_MILLIS_PER_SECOND;
34+ UDate now = uprv_getUTCtime();
35 int32_t raw, dst;
36 getOffset(now, FALSE, raw, dst, status);
37 if (dst != 0) {
38diff --git a/source/test/intltest/tztest.cpp b/source/test/intltest/tztest.cpp
39index 5ae9ae71..d949276b 100644
40--- a/source/test/intltest/tztest.cpp
41+++ b/source/test/intltest/tztest.cpp
42@@ -76,6 +76,8 @@ void TimeZoneTest::runIndexedTest( int32_t index, UBool exec, const char* &name,
43 TESTCASE_AUTO(TestGetGMT);
44 TESTCASE_AUTO(TestGetWindowsID);
45 TESTCASE_AUTO(TestGetIDForWindowsID);
46+ TESTCASE_AUTO(TestCasablancaNameAndOffset22041);
47+ TESTCASE_AUTO(TestRawOffsetAndOffsetConsistency22041);
48 TESTCASE_AUTO_END;
49 }
50
51@@ -2544,4 +2546,41 @@ void TimeZoneTest::TestGetIDForWindowsID(void) {
52 }
53 }
54
55+void TimeZoneTest::TestCasablancaNameAndOffset22041(void) {
56+ std::unique_ptr<TimeZone> zone(TimeZone::createTimeZone("Africa/Casablanca"));
57+ UnicodeString standardName, summerName;
58+ zone->getDisplayName(false, TimeZone::LONG, Locale::getEnglish(), standardName);
59+ zone->getDisplayName(true, TimeZone::LONG, Locale::getEnglish(), summerName);
60+ int32_t raw, dst;
61+ UErrorCode status = U_ZERO_ERROR;
62+ zone->getOffset(Calendar::getNow(), false, raw, dst, status);
63+ assertEquals(u"TimeZone name for Africa/Casablanca should not contain '+02' since it is located in UTC, but got "
64+ + standardName, -1, standardName.indexOf("+02"));
65+ assertEquals(u"TimeZone name for Africa/Casablanca should not contain '+02' since it is located in UTC, but got "
66+ + summerName, -1, summerName.indexOf("+02"));
67+ assertEquals("getRawOffset() and the raw from getOffset(now, false, raw, dst, status) should not be different but got",
68+ zone->getRawOffset(), raw);
69+}
70+
71+void TimeZoneTest::TestRawOffsetAndOffsetConsistency22041(void) {
72+ UErrorCode status = U_ZERO_ERROR;
73+ LocalPointer<StringEnumeration> s(TimeZone::createEnumeration(status));
74+ if (U_FAILURE(status)) {
75+ dataerrln("Unable to create TimeZone enumeration");
76+ return;
77+ }
78+ const char* tz;
79+ UDate now = Calendar::getNow();
80+ while ((tz = s->next(nullptr, status)) != nullptr && U_SUCCESS(status)) {
81+ std::unique_ptr<TimeZone> zone(TimeZone::createTimeZone(tz));
82+ int32_t raw, dst;
83+ zone->getOffset(now, false, raw, dst, status);
84+ if (U_FAILURE(status)) {
85+ errln("TimeZone '%s' getOffset() return error", tz);
86+ }
87+ assertEquals(u"TimeZone '" + UnicodeString(tz) +
88+ u"' getRawOffset() and the raw from getOffset(now, false, raw, dst, status) should not be different but got",
89+ zone->getRawOffset(), raw);
90+ }
91+}
92 #endif /* #if !UCONFIG_NO_FORMATTING */
93diff --git a/source/test/intltest/tztest.h b/source/test/intltest/tztest.h
94index 8e0a29fa..893aad65 100644
95--- a/source/test/intltest/tztest.h
96+++ b/source/test/intltest/tztest.h
97@@ -103,6 +103,8 @@ public:
98
99 void TestGetWindowsID(void);
100 void TestGetIDForWindowsID(void);
101+ void TestCasablancaNameAndOffset22041(void);
102+ void TestRawOffsetAndOffsetConsistency22041(void);
103
104 static const UDate INTERVAL;
105