< prev index next >
src/java.base/windows/native/libjava/TimeZone_md.c
Print this page
rev 51713 : [mq]: 8209167
@@ -34,10 +34,11 @@
#define VALUE_MAPID 2
#define VALUE_GMTOFFSET 3
#define MAX_ZONE_CHAR 256
#define MAX_MAPID_LENGTH 32
+#define MAX_REGION_LENGTH 4
#define NT_TZ_KEY "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones"
#define WIN_TZ_KEY "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Time Zones"
#define WIN_CURRENT_TZ_KEY "System\\CurrentControlSet\\Control\\TimeZoneInformation"
@@ -143,11 +144,11 @@
}
/*
* Gets the current time zone entry in the "Time Zones" registry.
*/
-static int getWinTimeZone(char *winZoneName, char *winMapID)
+static int getWinTimeZone(char *winZoneName)
{
DYNAMIC_TIME_ZONE_INFORMATION dtzi;
DWORD timeType;
DWORD bufSize;
DWORD val;
@@ -229,11 +230,10 @@
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;
@@ -370,28 +370,11 @@
}
out:
(void) RegCloseKey(hSubKey);
}
- /*
- * Get the "MapID" value of the registry to be able to eliminate
- * duplicated key names later.
- */
- valueSize = MAX_MAPID_LENGTH;
- ret = RegQueryValueExA(hSubKey, "MapID", NULL, &valueType, winMapID, &valueSize);
- (void) RegCloseKey(hSubKey);
(void) RegCloseKey(hKey);
-
- if (ret != ERROR_SUCCESS) {
- /*
- * Vista doesn't have mapID. VALUE_UNKNOWN should be returned
- * only for Windows NT.
- */
- if (onlyMapID == 1) {
- return VALUE_UNKNOWN;
- }
- }
}
return VALUE_KEY;
err:
@@ -408,39 +391,45 @@
/*
* Index values for the mapping table.
*/
#define TZ_WIN_NAME 0
-#define TZ_MAPID 1
-#define TZ_REGION 2
-#define TZ_JAVA_NAME 3
+#define TZ_REGION 1
+#define TZ_JAVA_NAME 2
-#define TZ_NITEMS 4 /* number of items (fields) */
+#define TZ_NITEMS 3 /* number of items (fields) */
/*
* Looks up the mapping table (tzmappings) and returns a Java time
* zone ID (e.g., "America/Los_Angeles") if found. Otherwise, NULL is
* returned.
- *
- * value_type is one of the following values:
- * VALUE_KEY for exact key matching
- * VALUE_MAPID for MapID (this is
- * required for the old Windows, such as NT 4.0 SP3).
*/
-static char *matchJavaTZ(const char *java_home_dir, int value_type, char *tzName,
- char *mapID)
+static char *matchJavaTZ(const char *java_home_dir, char *tzName)
{
int line;
int IDmatched = 0;
FILE *fp;
char *javaTZName = NULL;
char *items[TZ_NITEMS];
char *mapFileName;
char lineBuffer[MAX_ZONE_CHAR * 4];
- int noMapID = *mapID == '\0'; /* no mapID on Vista and later */
int offset = 0;
const char* errorMessage = "unknown error";
+ char region[MAX_REGION_LENGTH];
+
+ // Get the user's location
+ if (GetGeoInfo(GetUserGeoID(GEOCLASS_NATION),
+ GEO_ISO2, region, MAX_REGION_LENGTH, 0) == 0) {
+ // If GetGeoInfo fails, fallback to LCID's country
+ LCID lcid = GetUserDefaultLCID();
+ if (GetLocaleInfo(lcid,
+ LOCALE_SISO3166CTRYNAME, region, MAX_REGION_LENGTH) == 0 &&
+ GetLocaleInfo(lcid,
+ LOCALE_SISO3166CTRYNAME2, region, MAX_REGION_LENGTH) == 0) {
+ region[0] = '\0';
+ }
+ }
mapFileName = malloc(strlen(java_home_dir) + strlen(MAPPINGS_FILE) + 1);
if (mapFileName == NULL) {
return NULL;
}
@@ -492,32 +481,24 @@
errorMessage = "illegal non-newline character found";
offset = (int)(idx - lineBuffer);
goto illegal_format;
}
- if (noMapID || strcmp(mapID, items[TZ_MAPID]) == 0) {
/*
- * When there's no mapID, we need to scan items until the
+ * We need to scan items until the
* exact match is found or the end of data is detected.
*/
- if (!noMapID) {
- IDmatched = 1;
- }
if (strcmp(items[TZ_WIN_NAME], tzName) == 0) {
/*
* Found the time zone in the mapping table.
+ * Check the region code and select the appropriate entry
*/
+ if (strcmp(items[TZ_REGION], region) == 0 ||
+ strcmp(items[TZ_REGION], "001") == 0) {
javaTZName = _strdup(items[TZ_JAVA_NAME]);
break;
}
- } else {
- if (IDmatched == 1) {
- /*
- * No need to look up the mapping table further.
- */
- break;
- }
}
}
fclose(fp);
return javaTZName;
@@ -533,23 +514,20 @@
* Detects the platform time zone which maps to a Java time zone ID.
*/
char *findJavaTZ_md(const char *java_home_dir)
{
char winZoneName[MAX_ZONE_CHAR];
- char winMapID[MAX_MAPID_LENGTH];
char *std_timezone = NULL;
int result;
- winMapID[0] = 0;
- result = getWinTimeZone(winZoneName, winMapID);
+ result = getWinTimeZone(winZoneName);
if (result != VALUE_UNKNOWN) {
if (result == VALUE_GMTOFFSET) {
std_timezone = _strdup(winZoneName);
} else {
- std_timezone = matchJavaTZ(java_home_dir, result,
- winZoneName, winMapID);
+ std_timezone = matchJavaTZ(java_home_dir, winZoneName);
if (std_timezone == NULL) {
std_timezone = getGMTOffsetID();
}
}
}
< prev index next >