[TIMEDATE.CPL] In case TimeZone data does not contain a valid StandardName, perform comparisons against the time-zone numerical values instead.

It may happen that the time-zone information in the registry key
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation
contains an empty StandardName / DaylightName, or is too long for the
standard maximum 32-character length, and therefore is returned empty.
And/or it may happen as well that some of the standard names (value "Std")
present in some of the time zones listed in
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones
are similarly too long, and therefore are returned as empty strings.

In case this happens, perform comparisons instead with the numerical
values Bias, StandardBias, DaylightBias, StandardDate and DaylightDate
in order to find a match.

It is interesting to note also that in Vista+ there is an additional
REG_SZ value "TimeZoneKeyName" in
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation
that allows to directly find a match in the time zones list in
"Windows NT\CurrentVersion\Time Zones".
This commit is contained in:
Hermès Bélusca-Maïto 2020-04-22 00:16:14 +02:00
parent bbdb0ab6a8
commit aa69236646
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -168,10 +168,12 @@ ShowTimeZoneList(HWND hwnd)
{
TIME_ZONE_INFORMATION TimeZoneInfo;
PTIMEZONE_ENTRY Entry;
BOOL bDoAdvancedTest;
DWORD dwIndex;
DWORD i;
GetTimeZoneInformation(&TimeZoneInfo);
bDoAdvancedTest = (!*TimeZoneInfo.StandardName);
dwIndex = 0;
i = 0;
@ -183,8 +185,16 @@ ShowTimeZoneList(HWND hwnd)
0,
(LPARAM)Entry->Description);
if (!wcscmp(Entry->StandardName, TimeZoneInfo.StandardName))
if ( (!bDoAdvancedTest && *Entry->StandardName &&
wcscmp(Entry->StandardName, TimeZoneInfo.StandardName) == 0) ||
( (Entry->TimezoneInfo.Bias == TimeZoneInfo.Bias) &&
(Entry->TimezoneInfo.StandardBias == TimeZoneInfo.StandardBias) &&
(Entry->TimezoneInfo.DaylightBias == TimeZoneInfo.DaylightBias) &&
(memcmp(&Entry->TimezoneInfo.StandardDate, &TimeZoneInfo.StandardDate, sizeof(SYSTEMTIME)) == 0) &&
(memcmp(&Entry->TimezoneInfo.DaylightDate, &TimeZoneInfo.DaylightDate, sizeof(SYSTEMTIME)) == 0) ) )
{
dwIndex = i;
}
i++;
Entry = Entry->Next;