https://git.reactos.org/?p=reactos.git;a=commitdiff;h=d9cd76017336c2bc9d535807f56e5e80f7ac0d87
commit d9cd76017336c2bc9d535807f56e5e80f7ac0d87 Author: Hermès BÉLUSCA - MAÏTO <hermes.belusca-ma...@reactos.org> AuthorDate: Wed Sep 6 14:15:33 2023 +0200 Commit: GitHub <nore...@github.com> CommitDate: Wed Sep 6 14:15:33 2023 +0200 [TIMEDATE] Fix the way the current time-zone is found in the list. (#5649) fies regression CORE-18666 'Wrong timezone saved/displayed' which was introduced by 0.4.14-dev-1522-g aa69236646f01a476377ec76ae7b762e061cd300 --- dll/cpl/timedate/timezone.c | 65 ++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/dll/cpl/timedate/timezone.c b/dll/cpl/timedate/timezone.c index dcc8fab661a..8d1d94191fa 100644 --- a/dll/cpl/timedate/timezone.c +++ b/dll/cpl/timedate/timezone.c @@ -168,36 +168,51 @@ ShowTimeZoneList(HWND hwnd) { TIME_ZONE_INFORMATION TimeZoneInfo; PTIMEZONE_ENTRY Entry; - BOOL bDoAdvancedTest; - DWORD dwIndex; - DWORD i; + DWORD dwCount; + DWORD dwIndex = 0; + BOOL bFound = FALSE; - GetTimeZoneInformation(&TimeZoneInfo); - bDoAdvancedTest = (!*TimeZoneInfo.StandardName); + if (GetTimeZoneInformation(&TimeZoneInfo) == TIME_ZONE_ID_INVALID) + { + /* Failed to retrieve current time-zone info, reset it */ + ZeroMemory(&TimeZoneInfo, sizeof(TimeZoneInfo)); + } - dwIndex = 0; - i = 0; - Entry = TimeZoneListHead; - while (Entry != NULL) + for (Entry = TimeZoneListHead; Entry != NULL; Entry = Entry->Next) { - SendMessageW(hwnd, - CB_ADDSTRING, - 0, - (LPARAM)Entry->Description); - - 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) ) ) + dwCount = SendMessageW(hwnd, + CB_ADDSTRING, + 0, + (LPARAM)Entry->Description); + if (dwCount == CB_ERR || dwCount == CB_ERRSPACE) + continue; + + /* If the time-zone was found in the list, skip the tests */ + if (bFound) + continue; + + if (*TimeZoneInfo.StandardName && *Entry->StandardName) { - dwIndex = i; + /* Compare by name */ + if (wcscmp(Entry->StandardName, TimeZoneInfo.StandardName) == 0) + { + dwIndex = dwCount; + bFound = TRUE; + } + } + else + { + /* Compare by date and bias */ + if ((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 = dwCount; + bFound = TRUE; + } } - - i++; - Entry = Entry->Next; } SendMessageW(hwnd,