Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: uses of ucal_getHostTimeZone on systems that don't have it #36

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions windows/flutter_timezone_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,11 @@ namespace flutter_timezone {
/// </remarks>
void FlutterTimezonePlugin::GetLocalTimezone(
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>>& result) {
// This entire function body could be replaced with a call to `ucal_getHostTimeZone`.
// However, that function as only added in ICU 65, which is only available on Windows 11.
// Once we drop support for older Windows versions, this should be replaced.

// `ucal_getHostTimeZone` is only supported on Windows 10 21H2 or later, so we need to fetch
// the Windows time zone ourselves on older systems.
#if (NTDDI_VERSION >= 0x0A00000B) // NTDDI_WIN10_CO, 21H2
UErrorCode status = U_ZERO_ERROR;
UChar buffer[128];

// We ignore the status value and length result here; if this method fails, `buffer` will
// contain "Etc/Unknown", which is fine.
ucal_getHostTimeZone(buffer, ARRAYSIZE(buffer), &status);

std::wstring tz(buffer);
#pragma warning(suppress : 4244)
result->Success(std::string(tz.begin(), tz.end()));
#else
// Get the current Windows time zone
// Get the current Windows time zone
DYNAMIC_TIME_ZONE_INFORMATION tzInfo;
GetDynamicTimeZoneInformation(&tzInfo);

Expand Down Expand Up @@ -111,7 +100,6 @@ namespace flutter_timezone {
std::wstring tz(buffer);
#pragma warning(suppress : 4244)
result->Success(flutter::EncodableValue(std::string(tz.begin(), tz.end())));
#endif
}

/// <summary>
Expand Down
Loading