Debian Codegraph @

internal/gen_dm5abbrevs

raw
1 #!/usr/bin/perl -w
2 # Copyright (c) 2010-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 is used to automatically generate the Date::Manip::DM5abbrevs
9 # modeul used in Date::Manip 5.xx .
10
11 use lib "./lib";
12
13 require 5.010000;
14 use strict;
15 use warnings;
16
17 use Date::Manip::Zones;
18 use Date::Manip::TZ;
19
20 our($VERSION);
21 $VERSION='6.99';
22
23 our($DEBUG);
24 $DEBUG = 0;
25
26 our(@keep);
27 @keep = qw(
28 idlw -1200
29 nt -1100
30 sat -0400
31 cldt -0300
32 at -0200
33 utc +0000
34 mewt +0100
35 mez +0100
36 fwt +0100
37 gb +0100
38 swt +0100
39 mesz +0200
40 fst +0200
41 metdst +0200
42 eetdst +0300
43 eetedt +0300
44 bt +0300
45 it +0330
46 zp4 +0400
47 zp5 +0500
48 ist +0530
49 zp6 +0600
50 awst +0800
51 rok +0900
52 aest +1000
53 acdt +1030
54 cadt +1030
55 aedt +1100
56 eadt +1100
57 nzt +1200
58 idle +1200
59 );
60
61 ############################################################################
62 # MAIN PROGRAM
63 ############################################################################
64
65 my $year = ( localtime(time) )[5] + 1900;
66 my $tz = new Date::Manip::TZ;
67
68 my $podstr = '=pod'; # so the CPAN indexer won't treat this as a POD file
69
70 print "package Date::Manip::DM5abbrevs;
71 # Copyright (c) 2003-$year Sullivan Beck. All rights reserved.
72 # This program is free software; you can redistribute it and/or modify it
73 # under the same terms as Perl itself.
74
75 ########################################################################
76 ########################################################################
77
78 $podstr
79
80 =head1 NAME
81
82 Date::Manip::DM5abbrevs - A list of all timezone abbreviations
83
84 =head1 SYNPOSIS
85
86 This module is not intended to be used directly. Date::Manip 5.xx
87 will load it as needed.
88
89 This module contains all of the time zone abbreviations from
90 Date::Manip 6.xx copied backwards to 5.xx to provide slightly
91 better support for time zones.
92
93 Note that this is only a bandaid fix, and does not add proper
94 time zone handling to version 5.xx .
95
96 =cut
97
98 require 5.000;
99
100 use strict;
101 use warnings;
102
103 our(\$VERSION);
104 \$VERSION='$VERSION';
105
106 END {
107 my \$tmp;
108 \$tmp = \\\$Date::Manip::DM5::Abbrevs;
109 }
110
111 \$Date::Manip::DM5::Abbrevs = join(' ',qw(
112 ";
113
114 my @tmp = @keep;
115 my %off;
116 while (@tmp) {
117 my($abb) = shift(@tmp);
118 my($off) = shift(@tmp);
119 $off{$abb} = $off;
120 print " $abb" . " "x(6-length($abb)) . " $off\n";
121 }
122 print "\n";
123
124 # We have to come up with the best offset for each abbreviation.
125 #
126 # We'll look first at values in the current year.
127 # Then we'll look back in time.
128
129 ABBREV: foreach my $abbrev (sort keys %Date::Manip::Zones::Abbrev) {
130 my @zone = @{ $Date::Manip::Zones::Abbrev{$abbrev} };
131
132 foreach my $zone (@zone) {
133 my @period = $tz->all_periods($zone,$year);
134 foreach my $period (@period) {
135 my @per = @$period;
136 my $abb = lc($per[4]);
137 next if ($abb ne $abbrev);
138 my $off = $per[3];
139 my ($h,$m,$s) = @$off;
140 $h += 0;
141 next if ($s != 0);
142
143 my $sign;
144 if ($h < 0) {
145 $h *= -1;
146 $m *= -1;
147 $sign = "-";
148 } else {
149 $sign = "+";
150 }
151 $h = "0$h" if (length($h) == 1);
152 $m = "0$m" if (length($m) == 1);
153 $off = "$sign$h$m";
154
155 print " $abb" . " "x(6-length($abb)) . " $off\n";
156 $off{$abb} = $off;
157 next ABBREV;
158 }
159 }
160
161 # If we've arrived here, we didn't find the abbreviation in
162 # the current year, so we need to go back in time.
163
164 my $best_off = "";
165 my $best_date = "0001010100:00:00";
166
167 print ":: Abbrev = $abbrev...\n" if ($DEBUG);
168
169 ZONE:foreach my $zone (@zone) {
170 my @period = $tz->periods($zone,undef,$year);
171 while (@period) {
172 my $period = pop(@period);
173
174 my @per = @$period;
175 my $date = $per[10];
176 my $abb = lc($per[4]);
177 next if ($abb ne $abbrev);
178 my $off = $per[3];
179 my ($h,$m,$s) = @$off;
180 $h += 0;
181 next if ($s != 0);
182
183 my $sign;
184 if ($h < 0 ||
185 ($h == 0 && $m < 0)) {
186 $h *= -1;
187 $m *= -1;
188 $sign = "-";
189 } else {
190 $sign = "+";
191 }
192 $h = "0$h" if (length($h) == 1);
193 $m = "0$m" if (length($m) == 1);
194
195 if ($date lt $best_date) {
196 print ":: $zone => $best_off [ $best_date ]\n" if ($DEBUG);
197 next ZONE;
198 }
199
200 $best_off = "$sign$h$m";
201 $best_date = $date;
202
203 print ":: $zone => $best_off [ $best_date ] ***\n" if ($DEBUG);
204 next ZONE;
205 }
206 }
207
208 if ($best_off) {
209 $off{$abbrev} = $best_off;
210 print " $abbrev" . " "x(6-length($abbrev)) . " $best_off\n";
211 }
212 next ABBREV;
213 }
214
215 print "));
216
217 $podstr
218
219 =head1 TIMEZONES
220
221 The following timezones are defined:
222
223 ";
224
225 foreach my $abb (sort keys %off) {
226 my $off = $off{$abb};
227 print " " . uc($abb) . " "x(6-length($abb)) . " $off\n";
228 }
229
230 print "
231
232 =head1 LICENSE
233
234 This script is free software; you can redistribute it and/or modify it
235 under the same terms as Perl itself.
236
237 =head1 AUTHOR
238
239 Sullivan Beck (sbeck\@cpan.org)
240
241 =cut
242
243 1;
244 ";
245
246 # Local Variables:
247 # mode: cperl
248 # indent-tabs-mode: nil
249 # cperl-indent-level: 3
250 # cperl-continued-statement-offset: 2
251 # cperl-continued-brace-offset: 0
252 # cperl-brace-offset: 0
253 # cperl-brace-imaginary-offset: 0
254 # cperl-label-offset: 0
255 # End: