Debian Codegraph @

internal/windows.compare

raw
1 #!/usr/bin/perl
2 # Copyright (c) 2008-2026 Sullivan Beck. All rights reserved.
3 # This program is free software; you can redistribute it and/or modify it
4 # under the same terms as Perl itself.
5
6 ###############################################################################
7 ###############################################################################
8 # This script will check windows timezone information.
9
10 my $url = 'https://raw.githubusercontent.com/unicode-org/cldr/main/common/supplemental/windowsZones.xml';
11 my $new = 'windowsZones.xml';
12 require "./data.alias.pl";
13
14 use lib "../lib";
15 use Date::Manip::Zones;
16
17 # %Date::Manip::Zones::Alias
18 ############################################################################
19 # MAIN PROGRAM
20 ############################################################################
21
22 system("wget $url");
23 my %old = %windows_zones;
24 my %new = _parse($new);
25
26 # Find deprecated zones
27
28 my @old;
29 foreach my $key (keys %old) {
30 next if (exists $new{$key});
31 push(@old,$key);
32 }
33
34 if (@old) {
35 print "The following zones need to be removed:\n";
36 foreach my $key (sort @old) {
37 print " $key\n";
38 delete $old{$key};
39 }
40 print "\n";
41 }
42
43 # Find new zones
44
45 my @new;
46 foreach my $key (keys %new) {
47 next if (exists $old{$key});
48 push(@new,$key);
49 }
50
51 if (@new) {
52 print "The following zones need to be added (check that the zones are in tzdata):\n";
53 foreach my $key (sort @new) {
54 my $val = $new{$key};
55 print " \"$key\"" . " "x(32-length($key)) . "=> \"$val\",\n";
56 delete $new{$key};
57 }
58 print "\n";
59 }
60
61 # Find changed zones
62
63 my @chg;
64 foreach my $key (keys %old) {
65 next if ($old{$key} eq $new{$key});
66 push(@chg,$key);
67 }
68
69 if (@chg) {
70 print "The following zones need to be changed (verify in tzdata first):\n";
71 foreach my $key (sort @chg) {
72 my $val = $new{$key};
73 print " \"$key\"" . " "x(32-length($key)) . "=> \"$val\",\n";
74 }
75 print "\n";
76 }
77 unlink $new;
78
79 ############################################################################
80 ############################################################################
81
82 # Looks for lines of the form:
83 # <mapZone other="<ALIAS>" territory="<ABBREV>" type="<ZONE>"/>
84 # and creates
85 # ALIAS => ZONE
86 #
87 # ALIAS may be used mltiple times so only the first is used.
88 #
89 sub _parse {
90 my($file) = @_;
91 my %ret;
92
93 my @lines = `cat $file`;
94 chomp(@lines);
95
96 foreach my $line (@lines) {
97 if ($line =~ /<mapZone\s+other="(.*?)".*type="(.*?)"/) {
98 my($alias,$zone) = ($1,$2);
99
100 if (exists $Date::Manip::Zones::Alias{ lc($zone) }) {
101 $zone = $Date::Manip::Zones::Alias{ lc($zone) };
102 $zone = $Date::Manip::Zones::ZoneNames{$zone};
103 }
104 next if (exists $ret{$alias});
105 $ret{$alias} = $zone;
106 }
107 }
108
109 return %ret;
110 }
111
112 # Local Variables:
113 # mode: cperl
114 # indent-tabs-mode: nil
115 # cperl-indent-level: 3
116 # cperl-continued-statement-offset: 2
117 # cperl-continued-brace-offset: 0
118 # cperl-brace-offset: 0
119 # cperl-brace-imaginary-offset: 0
120 # cperl-label-offset: 0
121 # End: