Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit525449b

Browse files
committed
This patch attempts to fix the issue with localized timezones on
Windows.Recap: When running on a localized windows version, the timezone namereturned is also localized, and therefor does not match our lookuptable.Solution: The registry contains both the name of the timezone in englishand the localized name. The patch adds code to scan the registry for thelocalized name and gets the english name from that, and then rescans thetable.I have tested this on a Swedish WinXP, and it works without problems.The registry layout is the same in Win2k, but I haven't specificallytested it. It's also the same on different languages but again onlySwedish is tested.Magnus Hagander
1 parent528ac10 commit525449b

File tree

1 file changed

+105
-1
lines changed

1 file changed

+105
-1
lines changed

‎src/timezone/pgtz.c

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $PostgreSQL: pgsql/src/timezone/pgtz.c,v 1.25 2004/09/01 16:21:50 tgl Exp $
9+
* $PostgreSQL: pgsql/src/timezone/pgtz.c,v 1.26 2004/09/02 01:03:59 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -953,6 +953,110 @@ identify_system_timezone(void)
953953
}
954954
}
955955

956+
/*
957+
* Localized Windows versions return localized names for the
958+
* timezones. Scan the registry to find the english name,
959+
* and then try matching against the table again.
960+
*/
961+
ZeroMemory(localtzname,sizeof(localtzname));
962+
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
963+
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
964+
0,
965+
KEY_READ,
966+
&rootKey)!=ERROR_SUCCESS)
967+
{
968+
ereport(WARNING,
969+
(errmsg_internal("could not open registry key to identify Windows timezone \"%s\": %i",tzname, (int)GetLastError())));
970+
returnNULL;
971+
}
972+
973+
for (idx=0; ;idx++)
974+
{
975+
charkeyname[256];
976+
charzonename[256];
977+
DWORDnamesize=sizeof(keyname);
978+
FILETIMElastwrite;
979+
HKEYkey;
980+
LONGr;
981+
982+
ZeroMemory(keyname,sizeof(keyname));
983+
984+
if ((r=RegEnumKeyEx(rootKey,
985+
idx,
986+
keyname,
987+
&namesize,
988+
NULL,
989+
NULL,
990+
NULL,
991+
&lastwrite))!=ERROR_SUCCESS)
992+
{
993+
if (r==ERROR_NO_MORE_ITEMS)
994+
break;
995+
ereport(WARNING,
996+
(errmsg_internal("could not enumerate registry subkeys to identify Windows timezone \"%s\": %i",tzname, (int)r)));
997+
break;
998+
}
999+
1000+
if ((r=RegOpenKeyEx(rootKey,keyname,0,KEY_READ,&key))!=ERROR_SUCCESS)
1001+
{
1002+
ereport(WARNING,
1003+
(errmsg_internal("could not open registry subkey to identify Windows timezone \"%s\": %i",tzname, (int)r)));
1004+
break;
1005+
}
1006+
1007+
ZeroMemory(zonename,sizeof(zonename));
1008+
namesize=sizeof(zonename);
1009+
if ((r=RegQueryValueEx(key,"Std",NULL,NULL,zonename,&namesize))!=ERROR_SUCCESS)
1010+
{
1011+
ereport(WARNING,
1012+
(errmsg_internal("could not query value for 'std' to identify Windows timezone \"%s\": %i",tzname, (int)r)));
1013+
RegCloseKey(key);
1014+
break;
1015+
}
1016+
if (!strcmp(tzname,zonename))
1017+
{
1018+
/* Matched zone */
1019+
strcpy(localtzname,keyname);
1020+
RegCloseKey(key);
1021+
break;
1022+
}
1023+
ZeroMemory(zonename,sizeof(zonename));
1024+
namesize=sizeof(zonename);
1025+
if ((r=RegQueryValueEx(key,"Dlt",NULL,NULL,zonename,&namesize))!=ERROR_SUCCESS)
1026+
{
1027+
ereport(WARNING,
1028+
(errmsg_internal("could not query value for 'dlt' to identify Windows timezone \"%s\": %i",tzname, (int)r)));
1029+
RegCloseKey(key);
1030+
break;
1031+
}
1032+
if (!strcmp(tzname,zonename))
1033+
{
1034+
/* Matched DST zone */
1035+
strcpy(localtzname,keyname);
1036+
RegCloseKey(key);
1037+
break;
1038+
}
1039+
1040+
RegCloseKey(key);
1041+
}
1042+
1043+
RegCloseKey(rootKey);
1044+
1045+
if (localtzname[0])
1046+
{
1047+
/* Found a localized name, so scan for that one too */
1048+
for (i=0;win32_tzmap[i].stdname!=NULL;i++)
1049+
{
1050+
if (strcmp(localtzname,win32_tzmap[i].stdname)==0||
1051+
strcmp(localtzname,win32_tzmap[i].dstname)==0)
1052+
{
1053+
elog(DEBUG4,"TZ \"%s\" matches localized Windows timezone \"%s\" (\"%s\")",
1054+
win32_tzmap[i].pgtzname,tzname,localtzname);
1055+
returnwin32_tzmap[i].pgtzname;
1056+
}
1057+
}
1058+
}
1059+
9561060
ereport(WARNING,
9571061
(errmsg("could not find a match for Windows timezone \"%s\"",
9581062
tzname)));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp