ICU-6207 Cleaned up unused code. Minor improvements.

X-SVN-Rev: 24682
This commit is contained in:
Yoshito Umaoka 2008-09-30 19:18:59 +00:00
parent 382e5bb891
commit de92282fee
3 changed files with 76 additions and 822 deletions

View file

@ -29,27 +29,6 @@
# define NOMCX
#include <windows.h>
#if 0
/* Note: The structs and the macro definitions here are deprecated due to the
* new implementation not using any static tables. 9/15/2008 Michael Ow
*/
#define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
#define NEW_ARRAY(type,count) (type *) uprv_malloc((count) * sizeof(type))
#define DELETE_ARRAY(array) uprv_free((void *) (array))
#define ICUID_STACK_BUFFER_SIZE 32
typedef struct
{
const char *icuid;
const char *winid;
} WindowsICUMap;
typedef struct {
const char* winid;
const char* altwinid;
} WindowsZoneRemap;
#endif
/* The layout of the Tzi value in the registry */
typedef struct
{
@ -108,493 +87,6 @@ enum {
WIN_2K_XP_TYPE = 3
};
# if 0
/* Note: The static tables here are disabled and deprecated due to the new implementation
* using resource bundles instead. 9/15/2008 Michael Ow
*/
/*
* ZONE_MAP from supplementalData.txt
*/
static const WindowsICUMap NEW_ZONE_MAP[] = {
{"Africa/Cairo", "Egypt"},
{"Africa/Casablanca", "Greenwich"},
{"Africa/Johannesburg", "South Africa"},
{"Africa/Lagos", "W. Central Africa"},
{"Africa/Nairobi", "E. Africa"},
{"Africa/Windhoek", "Namibia"},
{"America/Anchorage", "Alaskan"},
{"America/Bogota", "SA Pacific"},
{"America/Buenos_Aires", "SA Eastern"},
{"America/Caracas", "SA Western"},
{"America/Chicago", "Central"},
{"America/Chihuahua", "Mountain Standard Time (Mexico)"},
{"America/Denver", "Mountain"},
{"America/Godthab", "Greenland"},
{"America/Guatemala", "Central America"},
{"America/Halifax", "Atlantic"},
{"America/Indianapolis", "US Eastern"},
{"America/Los_Angeles", "Pacific"},
{"America/Manaus", "Central Brazilian"},
{"America/Mexico_City", "Central Standard Time (Mexico)"},
{"America/Montevideo", "Montevideo"},
{"America/New_York", "Eastern"},
{"America/Noronha", "Mid-Atlantic"},
{"America/Phoenix", "US Mountain"},
{"America/Regina", "Canada Central"},
{"America/Santiago", "Pacific SA"},
{"America/Sao_Paulo", "E. South America"},
{"America/St_Johns", "Newfoundland"},
{"America/Tijuana", "Pacific Standard Time (Mexico)"},
{"Asia/Amman", "Jordan"},
{"Asia/Baghdad", "Arabic"},
{"Asia/Baku", "Azerbaijan"},
{"Asia/Bangkok", "SE Asia"},
{"Asia/Beirut", "Middle East"},
{"Asia/Calcutta", "India"},
{"Asia/Colombo", "Sri Lanka"},
{"Asia/Dhaka", "Central Asia"},
{"Asia/Jerusalem", "Israel"},
{"Asia/Kabul", "Afghanistan"},
{"Asia/Karachi", "West Asia"},
{"Asia/Katmandu", "Nepal"},
{"Asia/Krasnoyarsk", "North Asia"},
{"Asia/Muscat", "Arabian"},
{"Asia/Novosibirsk", "N. Central Asia"},
{"Asia/Rangoon", "Myanmar"},
{"Asia/Riyadh", "Arab"},
{"Asia/Seoul", "Korea"},
{"Asia/Shanghai", "China"},
{"Asia/Singapore", "Singapore"},
{"Asia/Taipei", "Taipei"},
{"Asia/Tbilisi", "Georgian"},
{"Asia/Tehran", "Iran"},
{"Asia/Tokyo", "Tokyo"},
{"Asia/Ulaanbaatar", "North Asia East"},
{"Asia/Vladivostok", "Vladivostok"},
{"Asia/Yakutsk", "Yakutsk"},
{"Asia/Yekaterinburg", "Ekaterinburg"},
{"Asia/Yerevan", "Caucasus"},
{"Atlantic/Azores", "Azores"},
{"Atlantic/Cape_Verde", "Cape Verde"},
{"Australia/Adelaide", "Cen. Australia"},
{"Australia/Brisbane", "E. Australia"},
{"Australia/Darwin", "AUS Central"},
{"Australia/Hobart", "Tasmania"},
{"Australia/Perth", "W. Australia"},
{"Australia/Sydney", "AUS Eastern"},
{"Europe/Berlin", "W. Europe"},
{"Europe/Helsinki", "FLE"},
{"Europe/Istanbul", "GTB"},
{"Europe/London", "GMT"},
{"Europe/Minsk", "E. Europe"},
{"Europe/Moscow", "Russian"},
{"Europe/Paris", "Romance"},
{"Europe/Prague", "Central Europe"},
{"Europe/Warsaw", "Central European"},
{"Pacific/Apia", "Samoa"},
{"Pacific/Auckland", "New Zealand"},
{"Pacific/Fiji", "Fiji"},
{"Pacific/Guadalcanal", "Central Pacific"},
{"Pacific/Guam", "West Pacific"},
{"Pacific/Honolulu", "Hawaiian"},
{"Pacific/Kwajalein", "Dateline"},
{"Pacific/Tongatapu", "Tonga"}
};
/* NOTE: Some Windows zone ids appear more than once. In such cases the
* ICU zone id from the first one is the preferred match.
*/
static const WindowsICUMap ZONE_MAP[] = {
/* S (GMT-12:00) International Date Line West */
{"Etc/GMT+12", "Dateline"},
/* S (GMT-11:00) Midway Island, Samoa */
{"Pacific/Apia", "Samoa"},
{"Pacific/Midway", "Samoa"},
/* S (GMT-10:00) Hawaii */
{"Pacific/Honolulu", "Hawaiian"},
/* D (GMT-09:00) Alaska */
{"America/Anchorage", "Alaskan"},
{"America/Juneau", "Alaskan"},
{"America/Yakutat", "Alaskan"},
{"America/Nome", "Alaskan"},
/* D (GMT-08:00) Pacific Time (US & Canada) */
{"America/Los_Angeles", "Pacific"},
{"America/Dawson", "Pacific"},
{"America/Vancouver", "Pacific"},
{"America/Whitehorse", "Pacific"},
/* D (GMT-08:00) Tijuana, Baja California */
{"America/Tijuana", "Pacific Standard Time (Mexico)"},
/* D (GMT-07:00) Mountain Time (US & Canada) */
{"America/Denver", "Mountain"},
{"America/Boise", "Mountain"},
{"America/Cambridge_Bay", "Mountain"},
{"America/Edmonton", "Mountain"},
{"America/Inuvik", "Mountain"},
{"America/Shiprock", "Mountain"},
{"America/Yellowknife", "Mountain"},
/* S (GMT-07:00) Arizona */
{"America/Phoenix", "US Mountain"},
/* D (GMT-07:00) Chihuahua, La Paz, Mazatlan */
{"America/Chihuahua", "Mountain Standard Time (Mexico)"},
{"America/Mazatlan", "Mountain Standard Time (Mexico)"},
/* D (GMT-06:00) Central Time (US & Canada) */
{"America/Chicago", "Central"},
{"America/Indiana/Knox", "Central"},
{"America/Indiana/Tell_City", "Central"},
{"America/Menominee", "Central"},
{"America/North_Dakota/Center", "Central"},
{"America/North_Dakota/New_Salem", "Central"},
{"America/Rainy_River", "Central"},
{"America/Rankin_Inlet", "Central"},
{"America/Winnipeg", "Central"},
/* D (GMT-06:00) Guadalajara, Mexico City, Monterrey */
{"America/Mexico_City", "Central Standard Time (Mexico)"},
{"America/Monterrey", "Central Standard Time (Mexico)"},
/* S (GMT-06:00) Central America */
{"America/Guatemala", "Central America"},
{"America/Belize", "Central America"},
{"America/Costa_Rica", "Central America"},
{"America/El_Salvador", "Central America"},
{"America/Managua", "Central America"},
{"America/Tegucigalpa", "Central America"},
{"Pacific/Galapagos", "Central America"},
/* S (GMT-06:00) Saskatchewan */
{"America/Regina", "Canada Central"},
{"America/Swift_Current", "Canada Central"},
/* D (GMT-05:00) Eastern Time (US & Canada) */
{"America/New_York", "Eastern"},
{"America/Detroit", "Eastern"},
{"America/Grand_Turk", "Eastern"},
{"America/Indiana/Marengo", "Eastern"},
{"America/Indiana/Petersburg", "Eastern"},
{"America/Indiana/Vevay", "Eastern"},
{"America/Indiana/Vincennes", "Eastern"},
{"America/Indiana/Winamac", "Eastern"},
{"America/Indianapolis", "Eastern"},
{"America/Iqaluit", "Eastern"},
{"America/Kentucky/Monticello", "Eastern"},
{"America/Louisville", "Eastern"},
{"America/Montreal", "Eastern"},
{"America/Nassau", "Eastern"},
{"America/Nipigon", "Eastern"},
{"America/Pangnirtung", "Eastern"},
{"America/Thunder_Bay", "Eastern"},
{"America/Toronto", "Eastern"},
/* S (GMT-05:00) Bogota, Lima, Quito, Rio Branco */
{"America/Bogota", "SA Pacific"},
{"America/Lima", "SA Pacific"},
{"America/Guayaquil", "SA Pacific"},
{"America/Rio_Branco", "SA Pacific"},
/* S (GMT-05:00) Indiana (East) */
{"Etc/GMT+5", "US Eastern"},
/* S (GMT-04:30) Caracas */
{"America/Caracas", "Venezuela"},
/* D (GMT-04:00) Atlantic Time (Canada) */
{"America/Halifax", "Atlantic"},
{"America/Glace_Bay", "Atlantic"},
{"America/Moncton", "Atlantic"},
/* D (GMT-04:00) Santiago */
{"America/Santiago", "Pacific SA"},
/* D (GMT-04:00) Manaus */ /* MS bug - DST is not used */
{"America/Manaus", "Central Brazilian"},
/* S (GMT-04:00) La Paz */
{"America/La_Paz", "SA Western"},
/* D (GMT-03:30) Newfoundland */
{"America/St_Johns", "Newfoundland"},
/* D (GMT-03:00) Brasilia */
{"America/Sao_Paulo", "E. South America"},
/* D (GMT-03:00) Buenos Aires */
{"America/Buenos_Aires", "Argentina"},
/* D (GMT-03:00) Greenland */
{"America/Godthab", "Greenland"},
/* D (GMT-03:00) Montevideo */
{"America/Montevideo", "Montevideo"},
/* S (GMT-03:00) Georgetown */ /* MS bug - Georgetown uses GMT-04:00 */
{"Etc/GMT+3", "SA Eastern"},
/* D (GMT-02:00) Mid-Atlantic */ /* MS bug - There is no such zone using GMT-02:00 with DST */
{"America/South_Georgia", "Mid-Atlantic"},
{"America/Noronha", "Mid-Atlantic"},
/* D (GMT-01:00) Azores */
{"Atlantic/Azores", "Azores"},
/* S (GMT-01:00) Cape Verde Is. */
{"Atlantic/Cape_Verde", "Cape Verde"},
/* D (GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London */
{"Europe/London", "GMT"},
{"Europe/Dublin", "GMT"},
{"Europe/Lisbon", "GMT"},
/* S (GMT) Casablanca, Monrovia, Reykjavik */
{"Africa/Casablanca", "Greenwich"},
{"Africa/Monrovia", "Greenwich"},
{"Atlantic/Reykjavik", "Greenwich"},
/* D (GMT+01:00) Brussels, Copenhagen, Madrid, Paris */
{"Europe/Paris", "Romance"},
{"Europe/Brussels", "Romance"},
{"Europe/Copenhagen", "Romance"},
{"Europe/Madrid", "Romance"},
/* D (GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna */
{"Europe/Berlin", "W. Europe"},
{"Europe/Amsterdam", "W. Europe"},
{"Europe/Zurich", "W. Europe"},
{"Europe/Rome", "W. Europe"},
{"Europe/Stockholm", "W. Europe"},
{"Europe/Vienna", "W. Europe"},
/* D (GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague */
{"Europe/Budapest", "Central Europe"},
{"Europe/Belgrade", "Central Europe"},
{"Europe/Bratislava", "Central Europe"},
{"Europe/Ljubljana", "Central Europe"},
{"Europe/Prague", "Central Europe"},
/* D (GMT+01:00) Sarajevo, Skopje, Warsaw, Zagreb */
{"Eurpoe/Warsaw", "Central European"},
{"Eurpoe/Sarajevo", "Central European"},
{"Eurpoe/Skopje", "Central European"},
{"Eurpoe/Zagreb", "Central European"},
/* S (GMT+01:00) West Central Africa */
{"Africa/Lagos", "W. Central Africa"},
{"Africa/Luanda", "W. Central Africa"},
{"Africa/Porto-Novo", "W. Central Africa"},
{"Africa/Douala", "W. Central Africa"},
{"Africa/Bangui", "W. Central Africa"},
{"Africa/Ndjamena", "W. Central Africa"},
{"Africa/Kinshasa", "W. Central Africa"},
{"Africa/Brazzaville", "W. Central Africa"},
{"Africa/Malabo", "W. Central Africa"},
{"Africa/Libreville", "W. Central Africa"},
{"Africa/Niamey", "W. Central Africa"},
/* D (GMT+02:00) Athens, Bucharest, Istanbul */
{"Europe/Istanbul", "GTB"},
{"Europe/Athens", "GTB"},
{"Europe/Bucharest", "GTB"},
/* D (GMT+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius */
{"Europe/Kiev", "FLE"},
{"Europe/Helsinki", "FLE"},
{"Europe/Riga", "FLE"},
{"Europe/Sofia", "FLE"},
{"Europe/Tallinn", "FLE"},
{"Europe/Vilnius", "FLE"},
/* D (GMT+02:00) Jerusalem */
{"Asia/Jerusalem", "Israel"},
/* D (GMT+02:00) Minsk */
{"Europe/Minsk", "E. Europe"},
/* D (GMT+02:00) Cairo */
{"Africa/Cairo", "Egypt"},
/* D (GMT+02:00) Amman */
{"Asia/Amman", "Jordan"},
/* D (GMT+02:00) Beirut */
{"Asia/Beirut", "Middle East"},
/* D (GMT+02:00) Windhoek */
{"Africa/Windhoek", "Namibia"},
/* S (GMT+02:00) Harare, Pretoria */
{"Africa/Johannesburg", "South Africa"},
{"Africa/Harare", "South Africa"},
/* D (GMT+03:00) Moscow, St. Petersburg, Volgograd */
{"Europe/Moscow", "Russian"},
{"Europe/Volgograd", "Russian"},
/* D (GMT+03:00) Baghdad */
{"Asia/Baghdad", "Arabic"},
/* S (GMT+03:00) Kuwait, Riyadh */
{"Asia/Riyadh", "Arab"},
{"Asia/Kuwait", "Arab"},
/* S (GMT+03:00) Nairobi */
{"Africa/Nairobi", "E. Africa"},
/* S (GMT+03:00) Tbilisi */ /* MS bug - Tbilisi uses GMT+04:00 */
{"Etc/GMT-3", "Georgian"},
/* D (GMT+03:30) Tehran */
{"Asia/Tehran", "Iran"},
/* D (GMT+04:00) Yerevan */
{"Asia/Yerevan", "Armenian"},
/* D (GMT+04:00) Baku */
{"Asia/Baku", "Azerbaijan"},
/* S (GMT+04:00) Abu Dhabi, Muscat */
{"Asia/Dubai", "Arabian"},
{"Asia/Muscat", "Arabian"},
/* S (GMT+04:00) Caucasus Standard Time */
{"Asia/Tbilisi", "Caucasus"},
/* S (GMT+04:30) Kabul */
{"Asia/Kabul", "Afghanistan"},
/* D (GMT+05:00) Ekaterinburg */
{"Asia/Yekaterinburg", "Ekaterinburg"},
/* S (GMT+05:00) Islamabad, Karachi, Tashkent */
{"Asia/Karachi", "West Asia"},
{"Asia/Tashkent", "West Asia"},
/* S (GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi */
{"Asia/Calcutta", "India"},
/* S (GMT+05:30) Sri Jayawardenepura */
{"Asia/Colombo", "Sri Lanka"},
/* S (GMT+05:45) Kathmandu */
{"Asia/Katmandu", "Nepal"},
/* D (GMT+06:00) Almaty, Novosibirsk */ /* No DST in Almaty */
{"Asia/Novosibirsk", "N. Central Asia"},
/* S (GMT+06:00) Astana, Dhaka */
{"Asia/Dhaka", "Central Asia"},
{"Asia/Almaty", "Central Asia"},
{"Asia/Qyzylorda", "Central Asia"},
/* S (GMT+06:30) Yangon (Rangoon) */
{"Asia/Rangoon", "Myanmar"},
/* D (GMT+07:00) Krasnoyarsk */
{"Asia/Krasnoyarsk", "North Asia"},
/* S (GMT+07:00) Bangkok, Hanoi, Jakarta */
{"Asia/Bangkok", "SE Asia"},
{"Asia/Saigon", "SE Asia"},
{"Asia/Jakarta", "SE Asia"},
/* D (GMT+08:00) Irkutsk, Ulaan Bataar */ /* Ulaan Bataar does not use DST */
{"Asia/Irkutsk", "North Asia East"},
/* D (GMT+08:00) Perth */
{"Australia/Perth", "W. Australia"},
/* S (GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi */
{"Asia/Shanghai", "China"},
{"Asia/Chongqing", "China"},
{"Asia/Hong_Kong", "China"},
{"Asia/Urumqi", "China"},
/* S (GMT+08:00) Taipei */
{"Asia/Taipei", "Taipei"},
/* S (GMT+08:00) Kuala Lumpur, Singapore */
{"Asia/Singapore", "Singapore"},
{"Asia/Kuala_Lumpur", "Singapore"},
/* D (GMT+09:00) Yakutsk */
{"Asia/Yakutsk", "Yakutsk"},
/* S (GMT+09:00) Osaka, Sapporo, Tokyo */
{"Asia/Tokyo", "Tokyo"},
/* S (GMT+09:00) Seoul */
{"Asia/Seoul", "Korea"},
/* D (GMT+09:30) Adelaide */
{"Australia/Adelaide", "Cen. Australia"},
/* S (GMT+09:30) Darwin */
{"Australia/Darwin", "AUS Central"},
/* D (GMT+10:00) Canberra, Melbourne, Sydney */
{"Australia/Sydney", "AUS Eastern"},
{"Australia/Melbourne", "AUS Eastern"},
/* D (GMT+10:00) Hobart */
{"Australia/Hobart", "Tasmania"},
/* D (GMT+10:00) Vladivostok */
{"Asia/Vladivostok", "Vladivostok"},
/* S (GMT+10:00) Brisbane */
{"Australia/Brisbane", "E. Australia"},
/* S (GMT+10:00) Guam, Port Moresby */
{"Pacific/Port_Moresby", "West Pacific"},
{"Pacific/Guam", "West Pacific"},
/* S (GMT+11:00) Magadan, Solomon Is., New Caledonia */ /* Magadan uses DST */
{"Pacific/Guadalcanal", "Central Pacific"},
{"Pacific/Noumea", "Central Pacific"},
/* D (GMT+12:00) Auckland, Wellington */
{"Pacific/Auckland", "New Zealand"},
/* S (GMT+12:00) Fiji, Kamchatka, Marshall Is. */
{"Pacific/Fiji", "Fiji"},
{"Pacific/Majuro", "Fiji"},
{"Pacific/Kwajalein", "Fiji"},
/* S (GMT+13:00) Nuku'alofa */
{"Pacific/Tongatapu", "Tonga"},
NULL, NULL
};
/**
* If a lookup fails, we attempt to remap certain Windows ids to
* alternate Windows ids. If the alternate listed here begins with
* '-', we use it as is (without the '-'). If it begins with '+', we
* append a " Standard Time" if appropriate.
*/
static const WindowsZoneRemap ZONE_REMAP[] = {
"Central European", "-Warsaw",
"Central Europe", "-Prague Bratislava",
"China", "-Beijing",
"Greenwich", "+GMT",
"GTB", "+GFT",
"Arab", "+Saudi Arabia",
"SE Asia", "+Bangkok",
"AUS Eastern", "+Sydney",
"Mountain Standard Time (Mexico)", "-Mexico Standard Time 2",
"Central Standard Time (Mexico)", "+Mexico",
NULL, NULL,
};
#endif
static int32_t gWinType = 0;
static int32_t detectWindowsType()
@ -624,45 +116,6 @@ static int32_t detectWindowsType()
return winType+1; // +1 to bring it inline with the enum
}
#if 0
/* Note: This is method is deprecated and disabled. See uprv_getWindowsTimeZoneInfo() below. */
/*
* TODO: Binary search sorted ZONE_MAP...
* (u_detectWindowsTimeZone() needs them sorted by offset...)
*/
static const char *findWindowsZoneID(const UChar *icuid, int32_t length)
{
char stackBuffer[ICUID_STACK_BUFFER_SIZE];
char *buffer = stackBuffer;
const char *result = NULL;
int i;
/*
* NOTE: >= because length doesn't include
* trailing null.
*/
if (length >= ICUID_STACK_BUFFER_SIZE) {
buffer = NEW_ARRAY(char, length + 1);
}
u_UCharsToChars(icuid, buffer, length);
buffer[length] = '\0';
for (i = 0; ZONE_MAP[i].icuid != NULL; i += 1) {
if (uprv_strcmp(buffer, ZONE_MAP[i].icuid) == 0) {
result = ZONE_MAP[i].winid;
break;
}
}
if (buffer != stackBuffer) {
DELETE_ARRAY(buffer);
}
return result;
}
#endif
static LONG openTZRegKey(HKEY *hkey, const char *winid)
{
char subKeyName[110]; /* TODO: why 96?? */
@ -678,12 +131,12 @@ static LONG openTZRegKey(HKEY *hkey, const char *winid)
name = &subKeyName[strlen(subKeyName)];
uprv_strcat(subKeyName, winid);
if (gWinType != WIN_9X_ME_TYPE &&
(winid[strlen(winid) - 1] != '2') &&
(winid[strlen(winid) - 1] != ')') &&
!(gWinType == WIN_NT_TYPE && strcmp(winid, "GMT") == 0))
{
/* uprv_strcat(subKeyName, STANDARD_TIME_REGKEY); */
if (gWinType == WIN_9X_ME_TYPE) {
/* Remove " Standard Time" */
char *pStd = uprv_strstr(subKeyName, STANDARD_TIME_REGKEY);
if (pStd) {
*pStd = 0;
}
}
result = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
@ -692,35 +145,6 @@ static LONG openTZRegKey(HKEY *hkey, const char *winid)
KEY_QUERY_VALUE,
hkey);
return result;
#if 0
/* Note: This portion of the code is deprecated due to the new implementation
* avoiding the use of static tables. Caution should be used in removing this
* code completely because the fallback method being implemented here may be
* actually be needed. Only after thorough testing should this code be removed.
* 9/15/2008 Michael Ow
*/
if (result != ERROR_SUCCESS) {
int i;
/* If the primary lookup fails, try to remap the Windows zone
ID, according to the remapping table. */
for (i=0; ZONE_REMAP[i].winid; i++) {
if (uprv_strcmp(winid, ZONE_REMAP[i].winid) == 0) {
uprv_strcpy(name, ZONE_REMAP[i].altwinid + 1);
if (*(ZONE_REMAP[i].altwinid) == '+' && gWinType != WIN_9X_ME_TYPE) {
uprv_strcat(subKeyName, STANDARD_TIME_REGKEY);
}
return RegOpenKeyExA(HKEY_LOCAL_MACHINE,
subKeyName,
0,
KEY_QUERY_VALUE,
hkey);
}
}
}
#endif
return result;
}
static LONG getTZI(const char *winid, TZI *tzi)
@ -746,35 +170,6 @@ static LONG getTZI(const char *winid, TZI *tzi)
return result;
}
#if 0
/* This method is deprecated and the new implementation, not using static tables, is in i18n\wintzimpl.h */
U_CAPI UBool U_EXPORT2
uprv_getWindowsTimeZoneInfo(TIME_ZONE_INFORMATION *zoneInfo, const UChar *icuid, int32_t length)
{
const char *winid;
TZI tzi;
LONG result;
winid = findWindowsZoneID(icuid, length);
if (winid != NULL) {
result = getTZI(winid, &tzi);
if (result == ERROR_SUCCESS) {
zoneInfo->Bias = tzi.bias;
zoneInfo->DaylightBias = tzi.daylightBias;
zoneInfo->StandardBias = tzi.standardBias;
zoneInfo->DaylightDate = tzi.daylightDate;
zoneInfo->StandardDate = tzi.standardDate;
return TRUE;
}
}
return FALSE;
}
#endif
/*
This code attempts to detect the Windows time zone, as set in the
Windows Date and Time control panel. It attempts to work on
@ -830,9 +225,7 @@ uprv_getWindowsTimeZoneInfo(TIME_ZONE_INFORMATION *zoneInfo, const UChar *icuid,
U_CFUNC const char* U_EXPORT2
uprv_detectWindowsTimeZone() {
UErrorCode status = U_ZERO_ERROR;
UResourceBundle* supplBundle = NULL;
UResourceBundle* mapTZBundle = NULL;
UResourceBundle* winTZBundle = NULL;
UResourceBundle* bundle = NULL;
char* icuid = NULL;
LONG result;
@ -853,15 +246,15 @@ uprv_detectWindowsTimeZone() {
uprv_memcpy((char *)&tziKey.daylightDate, (char*)&apiTZI.DaylightDate,
sizeof(apiTZI.DaylightDate));
supplBundle = ures_openDirect(NULL, "supplementalData", &status);
mapTZBundle = ures_getByKey(supplBundle, "mapTimezones", NULL, &status);
winTZBundle = ures_getByKey(mapTZBundle, "windows", NULL, &status);
bundle = ures_openDirect(NULL, "supplementalData", &status);
bundle = ures_getByKey(bundle, "mapTimezones", bundle, &status);
bundle = ures_getByKey(bundle, "windows", bundle, &status);
/* Note: We get the winid not from static tables but from resource bundle. */
while (U_SUCCESS(status) && ures_hasNext(winTZBundle)) {
while (U_SUCCESS(status) && ures_hasNext(bundle)) {
const char* winid;
int32_t len;
UResourceBundle* winTZ = ures_getNextResource(winTZBundle, NULL, &status);
UResourceBundle* winTZ = ures_getNextResource(bundle, NULL, &status);
if (U_FAILURE(status)) {
break;
}
@ -890,122 +283,9 @@ uprv_detectWindowsTimeZone() {
}
}
ures_close(winTZBundle);
ures_close(mapTZBundle);
ures_close(supplBundle);
ures_close(bundle);
return icuid;
#if 0
/* Note: The following is the original implementation and can be safely removed. 9/15/2008 Michael Ow */
HKEY hkey;
int firstMatch, lastMatch;
int j;
/* For each zone that can be identified by Offset+Rules, see if we
have a match. Continue scanning after finding a match,
recording the index of the first and the last match. We have
to do this because some zones are not unique under
Offset+Rules. */
firstMatch = -1;
lastMatch = -1;
for (j=0; ZONE_MAP[j].icuid; j++) {
const char* winid;
int32_t len;
winid = ures_getKey(winTZ);
result = getTZI(ZONE_MAP[j].winid, &tziReg);
if (result == ERROR_SUCCESS) {
/* Assume that offsets are grouped together, and bail out
when we've scanned everything with a matching
offset. */
if ( firstMatch >= 0 && tziKey.bias != tziReg.bias) {
break;
}
/* Windows alters the DaylightBias in some situations.
Using the bias and the rules suffices, so overwrite
these unreliable fields. */
tziKey.standardBias = tziReg.standardBias;
tziKey.daylightBias = tziReg.daylightBias;
if (uprv_memcmp((char *)&tziKey, (char*)&tziReg, sizeof(tziKey)) == 0) {
if (firstMatch < 0) {
firstMatch = j;
}
lastMatch = j;
}
}
}
/* This should never happen; if it does it means our table doesn't
match Windows AT ALL, perhaps because this is post-XP? */
if (firstMatch < 0) {
return NULL;
}
if (firstMatch != lastMatch) {
char stdName[32];
DWORD stdNameSize;
char stdRegName[64];
DWORD stdRegNameSize;
/* Offset+Rules lookup yielded >= 2 matches. Try to match the
localized display name. Get the name from the registry
(not the API). This avoids conversion issues. Use the
standard name, since Windows modifies the daylight name to
match the standard name if there is no DST. */
if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,
CURRENT_ZONE_REGKEY,
0,
KEY_QUERY_VALUE,
&hkey) == ERROR_SUCCESS)
{
stdNameSize = sizeof(stdName);
result = RegQueryValueExA(hkey,
STANDARD_NAME_REGKEY,
NULL,
NULL,
(LPBYTE)stdName,
&stdNameSize);
RegCloseKey(hkey);
/*
* Scan through the Windows time zone data in the registry
* again (just the range of zones with matching TZIs) and
* look for a standard display name match.
*/
for (j = firstMatch; j <= lastMatch; j += 1) {
stdRegNameSize = sizeof(stdRegName);
result = openTZRegKey(&hkey, ZONE_MAP[j].winid);
if (result == ERROR_SUCCESS) {
result = RegQueryValueExA(hkey,
STD_REGKEY,
NULL,
NULL,
(LPBYTE)stdRegName,
&stdRegNameSize);
}
RegCloseKey(hkey);
if (result == ERROR_SUCCESS &&
stdRegNameSize == stdNameSize &&
uprv_memcmp(stdName, stdRegName, stdNameSize) == 0)
{
firstMatch = j; /* record the match */
break;
}
}
} else {
RegCloseKey(hkey); /* should never get here */
}
}
return ZONE_MAP[firstMatch].icuid;
#endif
}
#endif /* #ifdef U_WINDOWS */

View file

@ -26,12 +26,6 @@ U_CDECL_BEGIN
typedef struct _TIME_ZONE_INFORMATION TIME_ZONE_INFORMATION;
U_CDECL_END
#if 0
/* This function is deprecated and is replaced by the function in i18n\wintzimpl.h */
U_CAPI UBool U_EXPORT2
uprv_getWindowsTimeZoneInfo(TIME_ZONE_INFORMATION *zoneInfo, const UChar *icuid, int32_t length);
#endif
U_CFUNC const char* U_EXPORT2
uprv_detectWindowsTimeZone();

View file

@ -18,7 +18,8 @@
#include "unicode/unistr.h"
#include "unicode/timezone.h"
#include "unicode/basictz.h"
#include "unicode/calendar.h"
#include "putilimp.h"
#include "uassert.h"
# define WIN32_LEAN_AND_MEAN
# define VC_EXTRALEAN
@ -32,93 +33,74 @@
static UBool getSystemTimeInformation(TimeZone *tz, SYSTEMTIME &daylightDate, SYSTEMTIME &standardDate, int32_t &bias, int32_t &daylightBias, int32_t &standardBias) {
UErrorCode status = U_ZERO_ERROR;
UBool result = TRUE;
BasicTimeZone *btz = NULL;
Calendar *cal = NULL;
BasicTimeZone *btz = (BasicTimeZone*)tz; // we should check type
InitialTimeZoneRule *initial = NULL;
AnnualTimeZoneRule *std = NULL;
AnnualTimeZoneRule *dst = NULL;
UDate currentTime;
int32_t currentYear;
int32_t rawOffset = tz->getRawOffset();
int32_t dstOffset = tz->getDSTSavings();
AnnualTimeZoneRule *std = NULL, *dst = NULL;
/* Offset set needs to be normalized so to Windows */
bias = (tz->getRawOffset() * -1)/(60000);
standardBias = 0;
if (tz->useDaylightTime()) {
daylightBias = (tz->getDSTSavings() / 60000) * -1;
} else {
daylightBias = 0;
}
btz = (BasicTimeZone *)tz->clone();
cal = Calendar::createInstance(tz, status);
if (btz != NULL && cal != NULL && U_SUCCESS(status)) {
currentTime = cal->getTime(status);
currentYear = cal->get(UCAL_YEAR, status);
btz->getSimpleRulesNear(currentTime, initial, std, dst, status);
if (U_SUCCESS(status)) {
if (std == NULL || dst == NULL) {
/* Generally, if std is NULL, dst will also be NULL.
* This indicates that daylight saving is not observed
* in this timezone so the standarDate and daylightDate
* should be zero.
*/
standardDate.wYear = standardDate.wMonth = standardDate.wDayOfWeek = standardDate.wDay =
standardDate.wHour = standardDate.wMinute = standardDate.wSecond = standardDate.wMilliseconds = 0;
daylightDate.wYear = daylightDate.wMonth = daylightDate.wDayOfWeek = daylightDate.wDay =
daylightDate.wHour = daylightDate.wMinute = daylightDate.wSecond = daylightDate.wMilliseconds = 0;
} else {
/* Get the UDate value for the start of the timezone standard time and daylight saving time.
* Then set the standardDate and daylightDate to this. The wYear value is 0 to indicate that
* this is not an absolute date but a rule. (e.g. the first Sunday in November)
*/
UDate dateTime;
if (std->getStartInYear(currentYear, rawOffset, 0, dateTime)) {
cal->setTime(dateTime, status);
standardDate.wYear = 0;
standardDate.wMonth = cal->get(UCAL_MONTH, status) + 1;
standardDate.wDayOfWeek = cal->get(UCAL_DAY_OF_WEEK, status) - 1;
standardDate.wDay = cal->get(UCAL_DAY_OF_WEEK_IN_MONTH, status);
standardDate.wHour = cal->get(UCAL_HOUR_OF_DAY, status);
standardDate.wMinute = cal->get(UCAL_MINUTE, status);
standardDate.wSecond = cal->get(UCAL_SECOND, status);
standardDate.wMilliseconds = cal->get(UCAL_MILLISECOND, status);
if (U_SUCCESS(status) && dst->getStartInYear(currentYear, rawOffset, dstOffset, dateTime)) {
cal->setTime(dateTime, status);
daylightDate.wYear = 0;
daylightDate.wMonth = cal->get(UCAL_MONTH, status) + 1;
daylightDate.wDayOfWeek = cal->get(UCAL_DAY_OF_WEEK, status) - 1;
daylightDate.wDay = cal->get(UCAL_DAY_OF_WEEK_IN_MONTH, status);
daylightDate.wHour = cal->get(UCAL_HOUR_OF_DAY, status) + dstOffset/3600000;
daylightDate.wMinute = cal->get(UCAL_MINUTE, status);
daylightDate.wSecond = cal->get(UCAL_SECOND, status);
daylightDate.wMilliseconds = cal->get(UCAL_MILLISECOND, status);
} else {
result = FALSE;
}
} else {
result = FALSE;
}
}
btz->getSimpleRulesNear(uprv_getUTCtime(), initial, std, dst, status);
if (U_SUCCESS(status)) {
if (std == NULL || dst == NULL) {
bias = -1 * (initial->getRawOffset()/60000);
daylightBias = 0;
// Do not use DST. Set 0 to all stadardDate/daylightDate fields
standardDate.wYear = standardDate.wMonth = standardDate.wDayOfWeek = standardDate.wDay =
standardDate.wHour = standardDate.wMinute = standardDate.wSecond = standardDate.wMilliseconds = 0;
daylightDate.wYear = daylightDate.wMonth = daylightDate.wDayOfWeek = daylightDate.wDay =
daylightDate.wHour = daylightDate.wMinute = daylightDate.wSecond = daylightDate.wMilliseconds = 0;
} else {
result = FALSE;
U_ASSERT(std->getRule()->getDateRuleType() == DateTimeRule::DOW);
U_ASSERT(dst->getRule()->getDateRuleType() == DateTimeRule::DOW);
bias = -1 * (std->getRawOffset()/60000);
daylightBias = -1 * (dst->getDSTSavings()/60000);
// Always use DOW type rule
int32_t hour, min, sec, mil;
standardDate.wYear = 0;
standardDate.wMonth = std->getRule()->getRuleMonth() + 1;
standardDate.wDay = std->getRule()->getRuleWeekInMonth();
if (standardDate.wDay < 0) {
standardDate.wDay = 5;
}
standardDate.wDayOfWeek = std->getRule()->getRuleDayOfWeek() - 1;
mil = std->getRule()->getRuleMillisInDay();
hour = mil/3600000;
mil %= 3600000;
min = mil/60000;
mil %= 60000;
sec = mil/1000;
mil %= 1000;
standardDate.wHour = hour;
standardDate.wMinute = min;
standardDate.wSecond = sec;
standardDate.wMilliseconds = mil;
daylightDate.wYear = 0;
daylightDate.wMonth = dst->getRule()->getRuleMonth() + 1;
daylightDate.wDay = dst->getRule()->getRuleWeekInMonth();
if (daylightDate.wDay < 0) {
daylightDate.wDay = 5;
}
daylightDate.wDayOfWeek = dst->getRule()->getRuleDayOfWeek() - 1;
mil = dst->getRule()->getRuleMillisInDay();
hour = mil/3600000;
mil %= 3600000;
min = mil/60000;
mil %= 60000;
sec = mil/1000;
mil %= 1000;
daylightDate.wHour = hour;
daylightDate.wMinute = min;
daylightDate.wSecond = sec;
daylightDate.wMilliseconds = mil;
}
} else {
result = FALSE;
}
if (result && U_FAILURE(status)) {
result = FALSE;
}
delete btz;
delete cal;
delete initial;
delete std;
delete dst;
@ -137,9 +119,7 @@ static UBool getWindowsTimeZoneInfo(TIME_ZONE_INFORMATION *zoneInfo, const UChar
int32_t standardBias;
SYSTEMTIME daylightDate;
SYSTEMTIME standardDate;
if (!getSystemTimeInformation(tz, daylightDate, standardDate, bias, daylightBias, standardBias)) {
result = FALSE;
} else {
if (getSystemTimeInformation(tz, daylightDate, standardDate, bias, daylightBias, standardBias)) {
zoneInfo->Bias = bias;
zoneInfo->DaylightBias = daylightBias;
zoneInfo->StandardBias = standardBias;