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

ICU-13842 Use GetDynamicTimeZoneInformation instead of Windows registry access in wintz.cpp #55

Merged

Conversation

mingyzha
Copy link
Contributor

@mingyzha mingyzha commented Aug 13, 2018

Use GetDynamicTimeZoneInformation instead of accessing the Windows registries so that it does not rely on COM in wintz. So that UWP apps could also use this code.

Checklist

@CLAassistant
Copy link

CLAassistant commented Aug 13, 2018

CLA assistant check
All committers have signed the CLA.

// This file contains only desktop Windows behavior
// Windows UWP calls Windows::Globalization directly, so this isn't needed there.
#if U_PLATFORM_USES_ONLY_WIN32_API && (U_PLATFORM_HAS_WINUWP_API == 0)
#if U_PLATFORM_USES_ONLY_WIN32_API || U_PLATFORM_HAS_WINUWP_API
Copy link

@axelandrejs axelandrejs Aug 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f U_PLATFORM_USES_ONLY_WIN32_API || U_PLATFORM_HAS_WINUWP_API [](start = 2, length = 61)

Doesn't this also require changes elsewhere, specifically in the caller? putil.cpp has this, which seems like it is wrong now:

#if U_PLATFORM_HAS_WINUWP_API == 0

include "wintz.h"

#else // U_PLATFORM_HAS_WINUWP_API
typedef PVOID LPMSG; // TODO: figure out how to get rid of this typedef
#include <Windows.Globalization.h>
#include <windows.system.userprofile.h>
#include <wrl/wrappers/corewrappers.h>
#include <wrl/client.h>

using namespace ABI::Windows::Foundation;
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
#endif

And then of course the actual call site. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new commits fixed the related codes for this change.


Author: Alan Liu
Since: ICU 2.6
Based on original code by Carl Brown <cbrown@xnetinc.com>

Modified on 8/13/2018
Copy link
Member

@jefgen jefgen Aug 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this comment.
I don't think any changes/modification history are recorded in the source comments anymore. (Or I haven't see anyone do this recently). I would suggest removing this comment, as the change history is stored in Git now.

icuid = (char*)uprv_calloc(len + 1, sizeof(char));
if (icuid != NULL)
{
uprv_strcpy(icuid, tmpid);
uprv_wcstombs(icuid, dynamicTZI.TimeZoneKeyName, len + 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite right. This will actually end up using wcstombs to convert the string, meaning that it will be converted from UTF-16 (wide string) to a code-page dependent string -- which isn't what you want at all.

@@ -36,174 +34,16 @@

#define MAX_LENGTH_ID 40
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest update uses it.

@@ -13,14 +13,12 @@

#include "unicode/utypes.h"

// This file contains only desktop Windows behavior
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is currently excluded from the UWP project file for the common project. If the plan is to replace the Windows.Globalization code with this API call (which is goodness), then you will need to modify the common_uwp.vcxproj file too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file is updated in the latest change.

{
UResourceBundle* winTZ = ures_getByKey(bundle, regStdName, NULL, &status);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you still need to look up the ICU time zone in the resources. You can't just take the Windows time zone string from the API and just return that.
You need to handle the Windows -> IANA/CLDR time zone mapping.

}
}

ures_close(bundle);

return icuid;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the mapping between the Windows Time zone names and the ICU Time zone names handled? I don't see it anywhere in here. In fact it looks like you deleted the code that currently does that. (Perhaps that was an accident?)

Copy link

@axelandrejs axelandrejs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕐

@axelandrejs axelandrejs dismissed their stale review August 20, 2018 23:02

revoking review

@@ -18,7 +18,7 @@

// This file contains only desktop windows behavior
// Windows UWP calls Windows::Globalization directly, so this isn't needed there.
Copy link
Member

@jefgen jefgen Aug 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is no longer correct. You should likely remove it. #Resolved

@@ -18,7 +18,7 @@

// This file contains only desktop windows behavior
// Windows UWP calls Windows::Globalization directly, so this isn't needed there.
#if U_PLATFORM_USES_ONLY_WIN32_API && (U_PLATFORM_HAS_WINUWP_API == 0)
#if U_PLATFORM_USES_ONLY_WIN32_API || U_PLATFORM_HAS_WINUWP_API

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could probably be changed to just U_PLATFORM_HAS_WIN32_API .

// This file contains only desktop Windows behavior
// Windows UWP calls Windows::Globalization directly, so this isn't needed there.
#if U_PLATFORM_USES_ONLY_WIN32_API && (U_PLATFORM_HAS_WINUWP_API == 0)
#if U_PLATFORM_USES_ONLY_WIN32_API || U_PLATFORM_HAS_WINUWP_API

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could likely be changed to just U_PLATFORM_HAS_WIN32_API.

if(ERROR_SUCCESS == result)
/* Convert the wchar_t* standard name to char* */
uprv_memset(dynamicTZKeyName, 0, sizeof(dynamicTZKeyName));
wcstombs(dynamicTZKeyName, dynamicTZI.TimeZoneKeyName, MAX_LENGTH_ID);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wcstombs [](start = 4, length = 8)

We still don't want to use/call this API. The results that it gives are OS-locale/codepage dependent, and the API that we are calling now is not.
GetDynamicTimeZoneInformation TimeZoneKeyName is UTF-16 encoded.

We should probably use something like u_strToUTF8 instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the PR here for an example of how to use it:
https://github.com/unicode-org/icu/pull/31/files


In reply to: 211446320 [](ancestors = 211446320)

@@ -36,219 +34,31 @@

#define MAX_LENGTH_ID 40
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAX_LENGTH_ID [](start = 8, length = 13)

Note: The size/number is not correct anymore.

TimeZoneKeyName can be up to 128 WCHARs long, so 40 is way to small now. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Thanks!

{
UErrorCode status = U_ZERO_ERROR;
UResourceBundle* bundle = NULL;
char* icuid = NULL;
char apiStdName[MAX_LENGTH_ID];
char regStdName[MAX_LENGTH_ID];
char dynamicTZKeyName[MAX_LENGTH_ID];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we zero init this like this?:
char dynamicTZKeyName[MAX_LENGTH_ID] = {};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Thanks!

Copy link
Member

@jefgen jefgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update @mingyzha !
It is looking better, but please take a look at the recent comments. Thanks!

SYSTEMTIME standardDate;
SYSTEMTIME daylightDate;
} TZI;
#define MAX_LENGTH_ID 128
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment for this define to indicate where the value comes from?
Nit: Also I wonder if MAX_TIMEZONE_ID_LENGTH might be slightly more clear? (Up to you)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments added. Thanks!

wcstombs(apiStdName, apiTZI.StandardName, MAX_LENGTH_ID);
/* Obtain TIME_ZONE_INFORMATION from the API and get the non-localized time zone name. */
uprv_memset(&dynamicTZI, 0, sizeof(dynamicTZI));
GetDynamicTimeZoneInformation(&dynamicTZI);
Copy link

@axelandrejs axelandrejs Aug 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetDynamicTimeZoneInformation [](start = 4, length = 29)

Check for failure? #Closed

@jefgen
Copy link
Member

jefgen commented Aug 23, 2018

Thanks @mingyzha!
Note: Please make sure to use the "Squash and merge" option, and also to manually edit the Title before merging to ensure that it has the ICU ticket number.

Copy link

@axelandrejs axelandrejs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@mingyzha mingyzha merged commit a3f8fc6 into unicode-org:master Aug 23, 2018
sffc pushed a commit to sffc/icu that referenced this pull request Sep 26, 2018
…ry access in wintz.cpp (unicode-org#55)

Use GetDynamicTimeZoneInformation instead of accessing the Windows registries so that it does not rely on COM in wintz. So that UWP apps could also use this code.
sffc pushed a commit to sffc/icu that referenced this pull request Sep 26, 2018
…ry access in wintz.cpp (unicode-org#55)

Use GetDynamicTimeZoneInformation instead of accessing the Windows registries so that it does not rely on COM in wintz. So that UWP apps could also use this code.
sffc pushed a commit to sffc/icu that referenced this pull request Sep 27, 2018
…ry access in wintz.cpp (unicode-org#55)

Use GetDynamicTimeZoneInformation instead of accessing the Windows registries so that it does not rely on COM in wintz. So that UWP apps could also use this code.
sffc pushed a commit to sffc/icu that referenced this pull request Sep 27, 2018
…ry access in wintz.cpp (unicode-org#55)

Use GetDynamicTimeZoneInformation instead of accessing the Windows registries so that it does not rely on COM in wintz. So that UWP apps could also use this code.
sffc pushed a commit to sffc/icu that referenced this pull request Sep 27, 2018
…ry access in wintz.cpp (unicode-org#55)

Use GetDynamicTimeZoneInformation instead of accessing the Windows registries so that it does not rely on COM in wintz. So that UWP apps could also use this code.
sffc pushed a commit to sffc/icu that referenced this pull request Sep 27, 2018
…ry access in wintz.cpp (unicode-org#55)

Use GetDynamicTimeZoneInformation instead of accessing the Windows registries so that it does not rely on COM in wintz. So that UWP apps could also use this code.
sharing-sense pushed a commit to sharing-sense/chromium-deps-icu that referenced this pull request Mar 13, 2019
This reverts commit ccad447 in M71
branch.

There's an issue with DST detection so that we revert it in M71 branch.
For M72 or later, we'll find a better fix.

> Fix the timezone detection on Windows with RDP.
>
> This is to cherry-pick fixes from the upstream to fix
> the timezone detection issue when a remote Windows
> session is used. The detected timezone should be that of
> a remote machine Chrome is running on, but without this
> fix, it uses the timezone of machine where a RDP connection
> originates.
>
> Bugs:
>
> https://unicode-org.atlassian.net/browse/ICU-13842
> https://unicode-org.atlassian.net/browse/ICU-13827
>
> Fixes (included in the upstream ICU 63 release candidate)
> unicode-org/icu#55
> unicode-org/icu#129
>
> TBR=yangguo@chromium.org
> Bug: 854387
> Test: Manual. See the bug
> Change-Id: Ic21e82987c1569e107d9b5e17bdc0d21e65fda3c
> Reviewed-on: https://chromium-review.googlesource.com/c/1270635

Bug: 854387, 913298
sharing-sense pushed a commit to sharing-sense/chromium-deps-icu that referenced this pull request Mar 13, 2019
…h RDP.""

This reverts commit 751b643, which reverted the following earlier commit
(ccad447) to deal with a regression on Windows 7 timezone detection.
(https://crbug.com/913298)

This CL will reintroduce the change made in ccad447 for bug 854387 to
M71 branch and be followed by the proper fix for bug 913298.

> Fix the timezone detection on Windows with RDP.
>
> This is to cherry-pick fixes from the upstream to fix
> the timezone detection issue when a remote Windows
> session is used. The detected timezone should be that of
> a remote machine Chrome is running on, but without this
> fix, it uses the timezone of machine where a RDP connection
> originates.
>
> Bugs:
>
> https://unicode-org.atlassian.net/browse/ICU-13842
> https://unicode-org.atlassian.net/browse/ICU-13827
>
> Fixes (included in the upstream ICU 63 release candidate)
> unicode-org/icu#55
> unicode-org/icu#129
>
> TBR=yangguo@chromium.org
> Bug: 854387
> Test: Manual. See the bug
> Change-Id: Ic21e82987c1569e107d9b5e17bdc0d21e65fda3c
> Reviewed-on: https://chromium-review.googlesource.com/c/1270635

Bug: 854387, 913298
Test: Manual. See the bug
hugovdm pushed a commit to hugovdm/icu that referenced this pull request Aug 17, 2020
…verter

add comment about ratesInfo param in UnitConverter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants