7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
Reviewed-by: peytoia
This commit is contained in:
parent
afdabb44dc
commit
204901217f
@ -147,76 +147,69 @@ static void customZoneName(LONG bias, char *buffer) {
|
|||||||
*/
|
*/
|
||||||
static int getWinTimeZone(char *winZoneName, char *winMapID)
|
static int getWinTimeZone(char *winZoneName, char *winMapID)
|
||||||
{
|
{
|
||||||
TIME_ZONE_INFORMATION tzi;
|
DYNAMIC_TIME_ZONE_INFORMATION dtzi;
|
||||||
OSVERSIONINFO ver;
|
|
||||||
int onlyMapID;
|
|
||||||
HANDLE hKey = NULL, hSubKey = NULL;
|
|
||||||
LONG ret;
|
|
||||||
DWORD nSubKeys, i;
|
|
||||||
ULONG valueType;
|
|
||||||
TCHAR subKeyName[MAX_ZONE_CHAR];
|
|
||||||
TCHAR szValue[MAX_ZONE_CHAR];
|
|
||||||
WCHAR stdNameInReg[MAX_ZONE_CHAR];
|
|
||||||
TziValue tempTzi;
|
|
||||||
WCHAR *stdNamePtr = tzi.StandardName;
|
|
||||||
DWORD valueSize;
|
|
||||||
DWORD timeType;
|
DWORD timeType;
|
||||||
int isVista;
|
DWORD bufSize;
|
||||||
|
DWORD val;
|
||||||
|
HANDLE hKey = NULL;
|
||||||
|
LONG ret;
|
||||||
|
ULONG valueType;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the current time zone setting of the platform.
|
* Get the dynamic time zone information so that time zone redirection
|
||||||
|
* can be supported. (see JDK-7044727)
|
||||||
*/
|
*/
|
||||||
timeType = GetTimeZoneInformation(&tzi);
|
timeType = GetDynamicTimeZoneInformation(&dtzi);
|
||||||
if (timeType == TIME_ZONE_ID_INVALID) {
|
if (timeType == TIME_ZONE_ID_INVALID) {
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Determine if this is an NT system.
|
* Make sure TimeZoneKeyName is available from the API call. If
|
||||||
|
* DynamicDaylightTime is disabled, return a custom time zone name
|
||||||
|
* based on the GMT offset. Otherwise, return the TimeZoneKeyName
|
||||||
|
* value.
|
||||||
*/
|
*/
|
||||||
ver.dwOSVersionInfoSize = sizeof(ver);
|
if (dtzi.TimeZoneKeyName[0] != 0) {
|
||||||
GetVersionEx(&ver);
|
if (dtzi.DynamicDaylightTimeDisabled) {
|
||||||
isVista = ver.dwMajorVersion >= 6;
|
customZoneName(dtzi.Bias, winZoneName);
|
||||||
|
return VALUE_GMTOFFSET;
|
||||||
|
}
|
||||||
|
wcstombs(winZoneName, dtzi.TimeZoneKeyName, MAX_ZONE_CHAR);
|
||||||
|
return VALUE_KEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If TimeZoneKeyName is not available, check whether StandardName
|
||||||
|
* is available to fall back to the older API GetTimeZoneInformation.
|
||||||
|
* If not, directly read the value from registry keys.
|
||||||
|
*/
|
||||||
|
if (dtzi.StandardName[0] == 0) {
|
||||||
ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_CURRENT_TZ_KEY, 0,
|
ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_CURRENT_TZ_KEY, 0,
|
||||||
KEY_READ, (PHKEY)&hKey);
|
KEY_READ, (PHKEY)&hKey);
|
||||||
if (ret == ERROR_SUCCESS) {
|
if (ret != ERROR_SUCCESS) {
|
||||||
DWORD val;
|
goto err;
|
||||||
DWORD bufSize;
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Determine if auto-daylight time adjustment is turned off.
|
* Determine if auto-daylight time adjustment is turned off.
|
||||||
*/
|
*/
|
||||||
valueType = 0;
|
|
||||||
bufSize = sizeof(val);
|
bufSize = sizeof(val);
|
||||||
ret = RegQueryValueExA(hKey, "DisableAutoDaylightTimeSet",
|
ret = RegQueryValueExA(hKey, "DynamicDaylightTimeDisabled", NULL,
|
||||||
NULL, &valueType, (LPBYTE) &val, &bufSize);
|
&valueType, (LPBYTE) &val, &bufSize);
|
||||||
/*
|
|
||||||
* Vista uses the different key name.
|
|
||||||
*/
|
|
||||||
if (ret != ERROR_SUCCESS) {
|
if (ret != ERROR_SUCCESS) {
|
||||||
bufSize = sizeof(val);
|
goto err;
|
||||||
ret = RegQueryValueExA(hKey, "DynamicDaylightTimeDisabled",
|
|
||||||
NULL, &valueType, (LPBYTE) &val, &bufSize);
|
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
if (ret == ERROR_SUCCESS) {
|
* Return a custom time zone name if auto-daylight time adjustment
|
||||||
int daylightSavingsUpdateDisabledOther = val == 1 && tzi.DaylightDate.wMonth != 0;
|
* is disabled.
|
||||||
int daylightSavingsUpdateDisabledVista = val == 1;
|
*/
|
||||||
int daylightSavingsUpdateDisabled = isVista ? daylightSavingsUpdateDisabledVista : daylightSavingsUpdateDisabledOther;
|
if (val == 1) {
|
||||||
|
customZoneName(dtzi.Bias, winZoneName);
|
||||||
if (daylightSavingsUpdateDisabled) {
|
|
||||||
(void) RegCloseKey(hKey);
|
(void) RegCloseKey(hKey);
|
||||||
customZoneName(tzi.Bias, winZoneName);
|
|
||||||
return VALUE_GMTOFFSET;
|
return VALUE_GMTOFFSET;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Vista has the key for the current "Time Zones" entry.
|
|
||||||
*/
|
|
||||||
if (isVista) {
|
|
||||||
valueType = 0;
|
|
||||||
bufSize = MAX_ZONE_CHAR;
|
bufSize = MAX_ZONE_CHAR;
|
||||||
ret = RegQueryValueExA(hKey, "TimeZoneKeyName", NULL,
|
ret = RegQueryValueExA(hKey, "TimeZoneKeyName", NULL,
|
||||||
&valueType, (LPBYTE) winZoneName, &bufSize);
|
&valueType, (LPBYTE) winZoneName, &bufSize);
|
||||||
@ -225,6 +218,42 @@ static int getWinTimeZone(char *winZoneName, char *winMapID)
|
|||||||
}
|
}
|
||||||
(void) RegCloseKey(hKey);
|
(void) RegCloseKey(hKey);
|
||||||
return VALUE_KEY;
|
return VALUE_KEY;
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Fall back to GetTimeZoneInformation
|
||||||
|
*/
|
||||||
|
TIME_ZONE_INFORMATION tzi;
|
||||||
|
HANDLE hSubKey = NULL;
|
||||||
|
DWORD nSubKeys, i;
|
||||||
|
ULONG valueType;
|
||||||
|
TCHAR subKeyName[MAX_ZONE_CHAR];
|
||||||
|
TCHAR szValue[MAX_ZONE_CHAR];
|
||||||
|
WCHAR stdNameInReg[MAX_ZONE_CHAR];
|
||||||
|
TziValue tempTzi;
|
||||||
|
WCHAR *stdNamePtr = tzi.StandardName;
|
||||||
|
DWORD valueSize;
|
||||||
|
int onlyMapID;
|
||||||
|
|
||||||
|
timeType = GetTimeZoneInformation(&tzi);
|
||||||
|
if (timeType == TIME_ZONE_ID_INVALID) {
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_CURRENT_TZ_KEY, 0,
|
||||||
|
KEY_READ, (PHKEY)&hKey);
|
||||||
|
if (ret == ERROR_SUCCESS) {
|
||||||
|
/*
|
||||||
|
* Determine if auto-daylight time adjustment is turned off.
|
||||||
|
*/
|
||||||
|
bufSize = sizeof(val);
|
||||||
|
ret = RegQueryValueExA(hKey, "DynamicDaylightTimeDisabled", NULL,
|
||||||
|
&valueType, (LPBYTE) &val, &bufSize);
|
||||||
|
if (ret == ERROR_SUCCESS) {
|
||||||
|
if (val == 1 && tzi.DaylightDate.wMonth != 0) {
|
||||||
|
(void) RegCloseKey(hKey);
|
||||||
|
customZoneName(tzi.Bias, winZoneName);
|
||||||
|
return VALUE_GMTOFFSET;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -233,8 +262,7 @@ static int getWinTimeZone(char *winZoneName, char *winMapID)
|
|||||||
* GetTimeZoneInformation() on NT returns a null string as its
|
* GetTimeZoneInformation() on NT returns a null string as its
|
||||||
* standard time name. We need to work around this problem by
|
* standard time name. We need to work around this problem by
|
||||||
* getting the same information from the TimeZoneInformation
|
* getting the same information from the TimeZoneInformation
|
||||||
* registry. The function on Win98 seems to return its key name.
|
* registry.
|
||||||
* We can't do anything in that case.
|
|
||||||
*/
|
*/
|
||||||
if (tzi.StandardName[0] == 0) {
|
if (tzi.StandardName[0] == 0) {
|
||||||
bufSize = sizeof(stdNameInReg);
|
bufSize = sizeof(stdNameInReg);
|
||||||
@ -362,6 +390,7 @@ static int getWinTimeZone(char *winZoneName, char *winMapID)
|
|||||||
return VALUE_UNKNOWN;
|
return VALUE_UNKNOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return VALUE_KEY;
|
return VALUE_KEY;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user