2010-04-15 13:00:45 +02:00
|
|
|
#################################################################
|
|
|
|
#
|
|
|
|
# win32tzlist.pl -- compare Windows timezone information
|
|
|
|
#
|
2022-01-08 01:04:57 +01:00
|
|
|
# Copyright (c) 2008-2022, PostgreSQL Global Development Group
|
2010-04-15 13:00:45 +02:00
|
|
|
#
|
2010-09-20 22:08:53 +02:00
|
|
|
# src/tools/win32tzlist.pl
|
2010-04-15 13:00:45 +02:00
|
|
|
#################################################################
|
|
|
|
|
|
|
|
#
|
2011-09-24 03:42:24 +02:00
|
|
|
# This script compares the timezone information in the Windows registry
|
|
|
|
# with that in src/bin/initdb/findtimezone.c. A list of changes will be
|
|
|
|
# written to stdout - no attempt is made to automatically edit the file.
|
2010-04-15 13:00:45 +02:00
|
|
|
#
|
2011-09-24 03:42:24 +02:00
|
|
|
# Run the script from the top-level PG source directory.
|
2010-04-15 13:00:45 +02:00
|
|
|
#
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Win32::Registry;
|
|
|
|
|
2011-09-24 03:42:24 +02:00
|
|
|
my $tzfile = 'src/bin/initdb/findtimezone.c';
|
|
|
|
|
2010-04-15 13:00:45 +02:00
|
|
|
#
|
|
|
|
# Fetch all timezones in the registry
|
|
|
|
#
|
|
|
|
my $basekey;
|
2012-07-05 03:47:49 +02:00
|
|
|
$HKEY_LOCAL_MACHINE->Open(
|
|
|
|
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones", $basekey)
|
2010-04-15 13:00:45 +02:00
|
|
|
or die $!;
|
|
|
|
|
|
|
|
my @subkeys;
|
|
|
|
$basekey->GetKeys(\@subkeys);
|
|
|
|
|
|
|
|
my @system_zones;
|
|
|
|
|
|
|
|
foreach my $keyname (@subkeys)
|
|
|
|
{
|
2012-07-05 03:47:49 +02:00
|
|
|
my $subkey;
|
|
|
|
my %vals;
|
|
|
|
|
|
|
|
$basekey->Open($keyname, $subkey) or die $!;
|
|
|
|
$subkey->GetValues(\%vals) or die $!;
|
|
|
|
$subkey->Close();
|
|
|
|
|
|
|
|
die "Incomplete timezone data for $keyname!\n"
|
|
|
|
unless ($vals{Std} && $vals{Dlt} && $vals{Display});
|
|
|
|
push @system_zones,
|
2018-05-09 16:14:46 +02:00
|
|
|
{
|
|
|
|
'std' => $vals{Std}->[2],
|
2012-07-05 03:47:49 +02:00
|
|
|
'dlt' => $vals{Dlt}->[2],
|
2018-05-09 16:14:46 +02:00
|
|
|
'display' => clean_displayname($vals{Display}->[2]),
|
|
|
|
};
|
2010-04-15 13:00:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$basekey->Close();
|
|
|
|
|
|
|
|
#
|
|
|
|
# Fetch all timezones currently in the file
|
|
|
|
#
|
|
|
|
my @file_zones;
|
2020-04-13 18:06:11 +02:00
|
|
|
my $pgtz;
|
2017-03-27 04:24:13 +02:00
|
|
|
open(my $tzfh, '<', $tzfile) or die "Could not open $tzfile!\n";
|
2020-04-13 18:06:11 +02:00
|
|
|
{
|
|
|
|
local $/ = undef;
|
|
|
|
$pgtz = <$tzfh>;
|
|
|
|
}
|
2017-03-27 04:24:13 +02:00
|
|
|
close($tzfh);
|
2010-04-15 13:00:45 +02:00
|
|
|
|
|
|
|
# Attempt to locate and extract the complete win32_tzmap struct
|
|
|
|
$pgtz =~ /win32_tzmap\[\] =\s+{\s+\/\*[^\/]+\*\/\s+(.+?)};/gs
|
2011-09-24 03:42:24 +02:00
|
|
|
or die "Could not locate struct win32_tzmap in $tzfile!";
|
2010-04-15 13:00:45 +02:00
|
|
|
$pgtz = $1;
|
|
|
|
|
|
|
|
# Extract each individual record from the struct
|
2012-07-05 03:47:49 +02:00
|
|
|
while ($pgtz =~
|
2020-04-24 23:21:44 +02:00
|
|
|
m/{\s+\/\*(.+?)\*\/\s+"([^"]+)",\s+"([^"]+)",\s+"([^"]+)",?\s+},/gs)
|
2010-04-15 13:00:45 +02:00
|
|
|
{
|
2012-07-05 03:47:49 +02:00
|
|
|
push @file_zones,
|
2018-05-09 16:14:46 +02:00
|
|
|
{
|
2020-04-24 23:21:44 +02:00
|
|
|
'display' => clean_displayname($1),
|
|
|
|
'std' => $2,
|
|
|
|
'dlt' => $3,
|
|
|
|
'match' => $4,
|
2018-05-09 16:14:46 +02:00
|
|
|
};
|
2010-04-15 13:00:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Look for anything that has changed
|
|
|
|
#
|
|
|
|
my @add;
|
|
|
|
|
|
|
|
for my $sys (@system_zones)
|
|
|
|
{
|
2012-07-05 03:47:49 +02:00
|
|
|
my $match = 0;
|
|
|
|
for my $file (@file_zones)
|
|
|
|
{
|
|
|
|
if ($sys->{std} eq $file->{std})
|
|
|
|
{
|
|
|
|
$match = 1;
|
|
|
|
if ($sys->{dlt} ne $file->{dlt})
|
|
|
|
{
|
|
|
|
print
|
|
|
|
"Timezone $sys->{std}, changed name of daylight zone!\n";
|
|
|
|
}
|
|
|
|
if ($sys->{display} ne $file->{display})
|
|
|
|
{
|
|
|
|
print
|
2018-04-26 17:52:52 +02:00
|
|
|
"Timezone $sys->{std} changed displayname ('$sys->{display}' from '$file->{display}')!\n";
|
2012-07-05 03:47:49 +02:00
|
|
|
}
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unless ($match)
|
|
|
|
{
|
|
|
|
push @add, $sys;
|
|
|
|
}
|
2010-04-15 13:00:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (@add)
|
|
|
|
{
|
2012-07-05 03:47:49 +02:00
|
|
|
print "\n\nOther than that, add the following timezones:\n";
|
|
|
|
for my $z (@add)
|
|
|
|
{
|
|
|
|
print
|
2020-04-24 23:53:23 +02:00
|
|
|
"\t{\n\t\t/* $z->{display} */\n\t\t\"$z->{std}\", \"$z->{dlt}\",\n\t\t\"FIXME\"\n\t},\n";
|
2012-07-05 03:47:49 +02:00
|
|
|
}
|
2010-04-15 13:00:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub clean_displayname
|
|
|
|
{
|
2012-07-05 03:47:49 +02:00
|
|
|
my $dn = shift;
|
2010-04-15 13:00:45 +02:00
|
|
|
|
2012-07-05 03:47:49 +02:00
|
|
|
$dn =~ s/\*//gs;
|
2020-04-24 23:21:44 +02:00
|
|
|
$dn =~ s/\s+/ /gs;
|
2012-07-05 03:47:49 +02:00
|
|
|
$dn =~ s/^\s+//gs;
|
|
|
|
$dn =~ s/\s+$//gs;
|
|
|
|
return $dn;
|
2010-04-15 13:00:45 +02:00
|
|
|
}
|