Skip to content

Commit 529ebfd

Browse files
authored
fix: uses of ucal_getHostTimeZone on systems that don't have it (#36)
The compile-time Windows version check is not a reliable way of checking whether the system has the `ucal_getHostTimeZone` function in its icu.dll. That function is only available since ICU 65, which only ships on Windows 11 and newer. Supporting that is not worth the hassle, so we keep the "manual" version (for now).
1 parent 67aab8e commit 529ebfd

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

windows/flutter_timezone_plugin.cpp

+4-16
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,11 @@ namespace flutter_timezone {
6363
/// </remarks>
6464
void FlutterTimezonePlugin::GetLocalTimezone(
6565
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>>& result) {
66+
// This entire function body could be replaced with a call to `ucal_getHostTimeZone`.
67+
// However, that function as only added in ICU 65, which is only available on Windows 11.
68+
// Once we drop support for older Windows versions, this should be replaced.
6669

67-
// `ucal_getHostTimeZone` is only supported on Windows 10 21H2 or later, so we need to fetch
68-
// the Windows time zone ourselves on older systems.
69-
#if (NTDDI_VERSION >= 0x0A00000B) // NTDDI_WIN10_CO, 21H2
70-
UErrorCode status = U_ZERO_ERROR;
71-
UChar buffer[128];
72-
73-
// We ignore the status value and length result here; if this method fails, `buffer` will
74-
// contain "Etc/Unknown", which is fine.
75-
ucal_getHostTimeZone(buffer, ARRAYSIZE(buffer), &status);
76-
77-
std::wstring tz(buffer);
78-
#pragma warning(suppress : 4244)
79-
result->Success(std::string(tz.begin(), tz.end()));
80-
#else
81-
// Get the current Windows time zone
70+
// Get the current Windows time zone
8271
DYNAMIC_TIME_ZONE_INFORMATION tzInfo;
8372
GetDynamicTimeZoneInformation(&tzInfo);
8473

@@ -111,7 +100,6 @@ namespace flutter_timezone {
111100
std::wstring tz(buffer);
112101
#pragma warning(suppress : 4244)
113102
result->Success(flutter::EncodableValue(std::string(tz.begin(), tz.end())));
114-
#endif
115103
}
116104

117105
/// <summary>

0 commit comments

Comments
 (0)