Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 17056e0

Browse files
committed
Add script to enumerate the timezones in the Windows registry and compare
it with the list we have in pgtz.c, showing any differences.
1 parent 7a7663f commit 17056e0

File tree

3 files changed

+144
-2
lines changed

3 files changed

+144
-2
lines changed

src/timezone/README

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$PostgreSQL: pgsql/src/timezone/README,v 1.8 2010/03/11 18:43:24 tgl Exp $
1+
$PostgreSQL: pgsql/src/timezone/README,v 1.9 2010/04/15 11:00:45 mha Exp $
22

33
Timezone
44
========
@@ -24,3 +24,10 @@ Just search for the current or previous year and see what has changed.
2424
Sometimes a country changes its time zone offsets, for example Georgia
2525
in 2004. Just grepping in the zic database files for 2004 is enough to
2626
spot such a change. Then the files under tznames/ should be updated.
27+
28+
When there has been a new release of Windows (probably including Service
29+
Packs), the list of matching timezones need to be updated. Run the
30+
script in src/tools/win32tzlist.pl on a Windows machine running this new
31+
release and apply any new timezones that it detects. Never remove any
32+
mappings in case they are removed in Windows, since we still need to
33+
match properly on the old version.

src/tools/RELEASE_CHANGES

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ For All Releases (major, minor, beta, RC)
1212
o add SGML markup
1313
o check if 'gmake HISTORY.html' works for <link>s
1414

15-
* Update timezone data to match latest zic database (see src/timezone/README)
15+
* Update timezone data to match latest zic database and new
16+
Windows releases, if any (see src/timezone/README)
1617

1718
* Translation updates
1819
Translations are kept in the project "pgtranslation" on PgFoundry.

src/tools/win32tzlist.pl

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#################################################################
2+
#
3+
# win32tzlist.pl -- compare Windows timezone information
4+
#
5+
# Copyright (c) 2008-2010, PostgreSQL Global Development Group
6+
#
7+
# $PostgreSQL: pgsql/src/tools/win32tzlist.pl,v 1.1 2010/04/15 11:00:45 mha Exp $
8+
#################################################################
9+
10+
#
11+
# This script compares the timezone information in the Windows
12+
# registry with that in pgtz.c. A list of changes will be written
13+
# to stdout - no attempt is made to automatically edit the file.
14+
#
15+
# Run the script from the src/timezone directory.
16+
#
17+
18+
use strict;
19+
use warnings;
20+
21+
use Win32::Registry;
22+
23+
#
24+
# Fetch all timezones in the registry
25+
#
26+
my $basekey;
27+
$HKEY_LOCAL_MACHINE->Open("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones", $basekey)
28+
or die $!;
29+
30+
my @subkeys;
31+
$basekey->GetKeys(\@subkeys);
32+
33+
my @system_zones;
34+
35+
foreach my $keyname (@subkeys)
36+
{
37+
my $subkey;
38+
my %vals;
39+
40+
$basekey->Open($keyname, $subkey) or die $!;
41+
$subkey->GetValues(\%vals) or die $!;
42+
$subkey->Close();
43+
44+
die "Incomplete timezone data for $keyname!\n"
45+
unless ($vals{Std} && $vals{Dlt} && $vals{Display});
46+
push @system_zones,
47+
{
48+
'std'=>$vals{Std}->[2],
49+
'dlt'=>$vals{Dlt}->[2],
50+
'display'=>clean_displayname($vals{Display}->[2]),
51+
};
52+
}
53+
54+
$basekey->Close();
55+
56+
#
57+
# Fetch all timezones currently in the file
58+
#
59+
my @file_zones;
60+
open(PGTZ,'<pgtz.c') or die "Could not open pgtz.c!\n";
61+
my $t = $/;
62+
undef $/;
63+
my $pgtz = <PGTZ>;
64+
close(PGTZ);
65+
$/ = $t;
66+
67+
# Attempt to locate and extract the complete win32_tzmap struct
68+
$pgtz =~ /win32_tzmap\[\] =\s+{\s+\/\*[^\/]+\*\/\s+(.+?)};/gs
69+
or die "Could not locate struct win32_tzmap in pgtz.c!";
70+
$pgtz = $1;
71+
72+
# Extract each individual record from the struct
73+
while ($pgtz =~ m/{\s+"([^"]+)",\s+"([^"]+)",\s+"([^"]+)",?\s+},\s+\/\*(.+?)\*\//gs)
74+
{
75+
push @file_zones,
76+
{
77+
'std'=>$1,
78+
'dlt'=>$2,
79+
'match'=>$3,
80+
'display'=>clean_displayname($4),
81+
};
82+
}
83+
84+
#
85+
# Look for anything that has changed
86+
#
87+
my @add;
88+
89+
for my $sys (@system_zones)
90+
{
91+
my $match = 0;
92+
for my $file (@file_zones)
93+
{
94+
if ($sys->{std} eq $file->{std})
95+
{
96+
$match=1;
97+
if ($sys->{dlt} ne $file->{dlt})
98+
{
99+
print "Timezone $sys->{std}, changed name of daylight zone!\n";
100+
}
101+
if ($sys->{display} ne $file->{display})
102+
{
103+
print
104+
"Timezone $sys->{std} changed displayname ('$sys->{display}' from '$file->{display}')!\n";
105+
}
106+
last;
107+
}
108+
}
109+
unless ($match)
110+
{
111+
push @add, $sys;
112+
}
113+
}
114+
115+
if (@add)
116+
{
117+
print "\n\nOther than that, add the following timezones:\n";
118+
for my $z (@add)
119+
{
120+
print
121+
"\t{\n\t\t\"$z->{std}\", \"$z->{dlt}\",\n\t\t\"FIXME\"\n\t},\t\t\t\t\t\t\t/* $z->{display} */\n";
122+
}
123+
}
124+
125+
sub clean_displayname
126+
{
127+
my $dn = shift;
128+
129+
$dn =~ s/\s+/ /gs;
130+
$dn =~ s/\*//gs;
131+
$dn =~ s/^\s+//gs;
132+
$dn =~ s/\s+$//gs;
133+
return $dn;
134+
}

0 commit comments

Comments
 (0)