Cherry-pick a Windows 7 timezone detection fix
Windows 7 has a 'bug' in one of its timezone APIs. ICU's
timezone detection code was hardened to work 'around' the
bug.
Upstream bug: https://unicode-org.atlassian.net/browse/ICU-20302
Upstream fix: https://github.com/unicode-org/icu/pull/315
TBR=gsathya@chromium.org,ftang@chromium.org
Bug: 913298
Test: See bug comment 35
Change-Id: Ib13b6a2809c629929490c5bfd73bee93b2c918c2
Reviewed-on: https://chromium-review.googlesource.com/c/1377557
Reviewed-by: Jungshik Shin <jshin@chromium.org>
diff --git a/README.chromium b/README.chromium
index e266952..6b5200e 100644
--- a/README.chromium
+++ b/README.chromium
@@ -274,3 +274,13 @@
https://unicode-org.atlassian.net/browse/ICU-11053
- Fix:
https://github.com/unicode-org/icu/pull/300
+
+12. Windows 7 timezone detection fix
+
+ - patches/win7_tz.patch
+ - upstream bug:
+ https://unicode-org.atlassian.net/browse/ICU-20302
+ - Fix:
+ https://github.com/unicode-org/icu/pull/315
+
+
diff --git a/patches/win7_tz.patch b/patches/win7_tz.patch
new file mode 100644
index 0000000..4406e6b
--- /dev/null
+++ b/patches/win7_tz.patch
@@ -0,0 +1,31 @@
+diff --git a/source/common/wintz.cpp b/source/common/wintz.cpp
+index 5e9ac0d2..8a143d9e 100644
+--- a/source/common/wintz.cpp
++++ b/source/common/wintz.cpp
+@@ -35,7 +35,7 @@
+
+ U_NAMESPACE_BEGIN
+
+-// The value of MAX_TIMEZONE_ID_LENGTH is 128, which is defined in DYNAMIC_TIME_ZONE_INFORMATION
++// The max size of TimeZoneKeyName is 128, defined in DYNAMIC_TIME_ZONE_INFORMATION
+ #define MAX_TIMEZONE_ID_LENGTH 128
+
+ /**
+@@ -44,7 +44,7 @@ U_NAMESPACE_BEGIN
+ * Note: We use the Win32 API GetDynamicTimeZoneInformation to get the current time zone info.
+ * This API returns a non-localized time zone name, which we can then map to an ICU time zone name.
+ */
+-U_CFUNC const char* U_EXPORT2
++U_INTERNAL const char* U_EXPORT2
+ uprv_detectWindowsTimeZone()
+ {
+ UErrorCode status = U_ZERO_ERROR;
+@@ -79,7 +79,7 @@ uprv_detectWindowsTimeZone()
+
+ // convert from wchar_t* (UTF-16 on Windows) to char* (UTF-8).
+ u_strToUTF8(dynamicTZKeyName, UPRV_LENGTHOF(dynamicTZKeyName), nullptr,
+- reinterpret_cast<const UChar*>(dynamicTZI.TimeZoneKeyName), UPRV_LENGTHOF(dynamicTZI.TimeZoneKeyName), &status);
++ reinterpret_cast<const UChar*>(dynamicTZI.TimeZoneKeyName), -1, &status);
+
+ if (U_FAILURE(status)) {
+ return nullptr;
diff --git a/source/common/wintz.cpp b/source/common/wintz.cpp
index 5e9ac0d..8a143d9 100644
--- a/source/common/wintz.cpp
+++ b/source/common/wintz.cpp
@@ -35,7 +35,7 @@
U_NAMESPACE_BEGIN
-// The value of MAX_TIMEZONE_ID_LENGTH is 128, which is defined in DYNAMIC_TIME_ZONE_INFORMATION
+// The max size of TimeZoneKeyName is 128, defined in DYNAMIC_TIME_ZONE_INFORMATION
#define MAX_TIMEZONE_ID_LENGTH 128
/**
@@ -44,7 +44,7 @@
* Note: We use the Win32 API GetDynamicTimeZoneInformation to get the current time zone info.
* This API returns a non-localized time zone name, which we can then map to an ICU time zone name.
*/
-U_CFUNC const char* U_EXPORT2
+U_INTERNAL const char* U_EXPORT2
uprv_detectWindowsTimeZone()
{
UErrorCode status = U_ZERO_ERROR;
@@ -79,7 +79,7 @@
// convert from wchar_t* (UTF-16 on Windows) to char* (UTF-8).
u_strToUTF8(dynamicTZKeyName, UPRV_LENGTHOF(dynamicTZKeyName), nullptr,
- reinterpret_cast<const UChar*>(dynamicTZI.TimeZoneKeyName), UPRV_LENGTHOF(dynamicTZI.TimeZoneKeyName), &status);
+ reinterpret_cast<const UChar*>(dynamicTZI.TimeZoneKeyName), -1, &status);
if (U_FAILURE(status)) {
return nullptr;