Debian Codegraph @

internal/tzdata

raw
1 #!/usr/bin/perl -w
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 is used to automatically generate the Date::Manip::Zones
9 # and Date::Manip::TZ::_ZONE_ modules from the original time zone data.
10
11 use lib "./lib";
12 use lib "./internal";
13
14 require 5.010000;
15 use YAML::XS;
16 use IO::File;
17 use Date::Manip::Base;
18 use Date::Manip::TZdata;
19 use strict;
20 use warnings;
21
22 our $VERSION;
23 $VERSION='6.99';
24
25 our ($dmb);
26 $dmb = new Date::Manip::Base;
27
28 our $curry = ( localtime(time) )[5] + 1900;
29
30 ##############################################################################
31 # GLOBAL VARIABLES
32 ###############################################################################
33
34 our ($first_date,$last_date,$tzdata_src,$tzdata_dir,$tzdata_data,$tzdata_code,
35 $mod_dir,$off_dir,
36 $curr_year,$keep_year,$test_year,$zones_pm,$zones_pod,
37 %def_off,%nontzdata_zones,%def_alias2,%def_abbrev,%no_last,
38 %last_zone_offsets
39 );
40
41 # The first and last dates (UT) known by this module (everything in the
42 # 0001 - 9999 range except for the first and last 24 hours of that range).
43
44 $first_date = "0001010200:00:00";
45 $last_date = "9999123100:00:00";
46
47 # The source for the tzdata/tzcode files:
48
49 $tzdata_src = "ftp.iana.org";
50 $tzdata_dir = "tz";
51 $tzdata_data= "tzdata-latest.tar.gz";
52 $tzdata_code= "tzcode-latest.tar.gz";
53
54
55 require "data.offset.pl";
56 require "data.abbrev.pl";
57 require "data.alias.pl";
58 require "data.misc.pl";
59
60 # so the CPAN indexer won't treat this as a POD file
61 our $podstr = '=pod';
62 our $hdstr = '=head1';
63
64 ###############################################################################
65 # HELP
66 ###############################################################################
67
68 our ($usage);
69 my $COM = $0;
70 $COM =~ s/^.*\///;
71
72 $usage=
73 "usage: $COM OPTIONS
74 -h/--help : Print help.
75 -v/--verbose : Increasing levels of verbosity
76
77 -a/--all : Do all steps
78
79 -f/--ftp : Download the tzdata/tzcode files from
80 the source and build the tools
81 -l/--list : Get a list of all time zones to dump
82 -d/--dump : This dumps out zone info for all of
83 the zones
84 -m/--mods : This creates the modules from the dumps
85 -o/--offset : Creates the offset modules
86 -z/--zones : Create the zones module
87 -c/--clean : Removes tzdata files
88 ";
89
90 ###############################################################################
91 # PARSE ARGUMENTS
92 ###############################################################################
93
94 our ($verbose);
95 $verbose = 0;
96 my $do_all = 0;
97 my $do_ftp = 0;
98 my $do_build = 0;
99 my $do_list = 0;
100 my $do_dump = 0;
101 my $do_mods = 0;
102 my $do_off = 0;
103 my $do_zones = 0;
104 my $do_clean = 0;
105
106 while ($_ = shift) {
107
108 (print $usage), exit if ($_ eq "-h" || $_ eq "--help");
109 $verbose = 1, next if ($_ eq "-v" || $_ eq "--verbose");
110
111 $do_all = 1, next if ($_ eq "-a" || $_ eq "--all");
112
113 $do_ftp = 1, next if ($_ eq "-f" || $_ eq "--ftp");
114 $do_build = 1, next if ($_ eq "-b" || $_ eq "--build");
115 $do_list = 1, next if ($_ eq "-l" || $_ eq "--list");
116 $do_dump = 1, next if ($_ eq "-d" || $_ eq "--dump");
117 $do_mods = 1, next if ($_ eq "-m" || $_ eq "--mods");
118 $do_off = 1, next if ($_ eq "-o" || $_ eq "--offset");
119 $do_zones = 1, next if ($_ eq "-z" || $_ eq "--zones");
120 $do_clean = 1, next if ($_ eq "-c" || $_ eq "--clean");
121 }
122
123 ############################################################################
124 # MAIN PROGRAM
125 ############################################################################
126
127 do_ftp() if ($do_all || $do_ftp);
128 do_build() if ($do_all || $do_build);
129 do_list() if ($do_all || $do_list);
130 do_dump() if ($do_all || $do_dump);
131 do_mods() if ($do_all || $do_mods);
132 do_off() if ($do_all || $do_off);
133 do_zones() if ($do_all || $do_zones);
134 do_clean() if ( $do_clean);
135
136 ############################################################################
137 # DO_FTP
138 ############################################################################
139
140 # FTP the tzdata/tzcode packages
141 #
142 sub do_ftp {
143 print "FTP...\n";
144
145 system("rm -rf tzdata; mkdir tzdata");
146 chdir("tzdata");
147
148 #
149 # Get the tz*latest.tar.gz links to determine the versions
150 #
151
152 system("wget -q 'ftp://$tzdata_src/$tzdata_dir/$tzdata_data' " .
153 "'ftp://$tzdata_src/$tzdata_dir/$tzdata_code'");
154 if (! -f $tzdata_data) {
155 die "ERROR: unable to ftp data. Try again later.";
156 }
157 if (! -f $tzdata_code) {
158 die "ERROR: unable to ftp code. Try again later.";
159 }
160
161 system("tar xzf $tzdata_data");
162 my $tzdata_vers = _release('data');
163
164 system("tar xzf $tzdata_code");
165 my $tzcode_vers = _release('code');
166
167 print " TZdata : $tzdata_vers\n";
168 print " Tzcode : $tzcode_vers\n";
169
170 system("echo $tzdata_vers > _version; " .
171 "echo $tzcode_vers >> _version; ");
172 }
173
174 sub _release {
175 my($type) = @_;
176 if (! -f 'NEWS') {
177 die "ERROR: unable to determine version (no NEWS): $type\n";
178 }
179 my $vers = `grep Release NEWS | head -1 | awk '{print \$2}'`;
180 chomp($vers);
181 if ($vers !~ /^\d\d\d\d[a-z]$/) {
182 die "ERROR: uknown version format: $type: $vers\n";
183 }
184 system("mv NEWS NEWS.$type");
185 return $vers;
186 }
187
188 # Build the package
189 #
190 sub do_build {
191 print "Build...\n";
192
193 system("cd tzdata; " .
194 "touch NEWS; " .
195 "make TOPDIR=./tmp INSTALL;");
196 }
197
198 ############################################################################
199 # DO_LIST
200 ############################################################################
201
202 # Get a list of all zones in the tzdata files which we will create
203 # modules for. Store a list of them and the associated module name.
204 #
205 # Stored in: _zone
206 #
207 sub do_list {
208 print "List...\n";
209
210 #
211 # Get a list of zones from all Zone lines in the standard files in
212 # the tzdata package.
213 #
214
215 my(@zone,@link);
216
217 foreach my $file (@Date::Manip::TZdata::StdFiles) {
218 my @tmp = `grep '^Zone' tzdata/$file | awk '{print \$2}'`;
219 chomp(@tmp);
220 push(@zone,@tmp);
221
222 @tmp = `grep '^Link' tzdata/$file | awk '{print \$2,\$3}'`;
223 chomp(@tmp);
224 push(@link,@tmp);
225 }
226
227 #
228 # Generate a module name for every zone (excepting some which
229 # we're ignoring, or creating in other ways).
230 #
231
232 my %module = ();
233 my %modname = ();
234 my %alias = ();
235 foreach my $zone (sort @zone) {
236 next if (exists $nontzdata_zones{$zone} ||
237 exists $def_alias2{$zone});
238 my $module = _do_list_modname(\%modname,$zone);
239 $module{$zone} = [ $module, "tzdata" ];
240 $alias{$zone} = [ $zone, "tzdata" ];
241 }
242
243 #
244 # Generate a module name for every zone which is created as
245 # an offset (e.g. GMT-3).
246 #
247
248 foreach my $zone (sort keys %nontzdata_zones) {
249 my($type,$val) = @{ $nontzdata_zones{$zone} };
250 if ($type eq "offset") {
251 my $module = _do_list_modname(\%modname,$zone);
252 $module{$zone} = [ $module, "offset", $val ];
253 $alias{$zone} = [ $zone, "offset" ];
254 }
255 }
256
257 #
258 # Handle all other special cases such as special aliases and
259 # ignored zones.
260 #
261
262 foreach my $zone (sort keys %nontzdata_zones) {
263 my($type,$val) = @{ $nontzdata_zones{$zone} };
264 if ($type eq "offset") {
265 next;
266 } elsif ($type eq "alias") {
267 warn "[do_list] unknown alias [$zone: $val]\n"
268 if (! exists $module{$val});
269 $alias{$zone} = [ $val, $type ];
270 } elsif ($type eq "ignore") {
271 $alias{$zone} = [ $val, $type ];
272 } else {
273 warn "[do_list] unknown type [$zone: $type]\n";
274 }
275 }
276
277 foreach my $link (@link) {
278 my($zone,$alias) = split(/\s+/,$link);
279 $alias{$alias} = [ $zone, "alias" ];
280 }
281
282 # Write out the official list of zones and aliases.
283
284 _yaml_write(\%module,"tzdata/_zone_list",0);
285 _yaml_write(\%alias, "tzdata/_alias_list",0);
286 }
287
288 # Takes a hashref $module{MODNAME} = ZONE and a zone and comes up
289 # with a unique module name for it. It returns the name of the module
290 # (as well as adds it to the hash).
291 #
292 sub _do_list_modname {
293 my($modnames,$zone) = @_;
294
295 my $modname = "";
296 if ($zone =~ /\//) {
297 my @tmp = split(/\//,$zone);
298 $modname = substr($tmp[0],0,2) . substr($tmp[$#tmp],0,4);
299 } else {
300 $modname = substr($zone,0,6);
301 }
302 $modname =~ s/\-/m/g;
303 $modname =~ s/\+/p/g;
304
305 my $i = "00";
306 while (exists $$modnames{"$modname$i"}) {
307 $i++;
308 }
309 $modname .= $i;
310 $$modnames{$modname} = 1;
311 return lc($modname);
312 }
313
314 ############################################################################
315 # DO_DUMP
316 ############################################################################
317
318 # Dump every zone.
319 #
320 # Stored in: dump/MODNAME
321 #
322 sub do_dump {
323 print "Dump...\n";
324
325 my $tmp = _yaml_read("tzdata/_zone_list");
326 my %module = %$tmp;
327 my $num = keys %module;
328 my $len = length($num);
329 my $i = 0;
330
331 system("rm -rf tzdata/dump; " .
332 "mkdir tzdata/dump");
333
334 print " dumping "," "x($len-length($i)),"$i / $num";
335
336 foreach my $zone (keys %module) {
337 $i++;
338 print "\010"x($len*2+3)," "x($len-length($i)),"$i / $num";
339 my($module,$type) = @{ $module{$zone} };
340 next if ($type ne "tzdata");
341 my $cmd = "cd tzdata; ./zdump -c $test_year -V $zone > dump/$module";
342 print " $cmd\n" if ($verbose);
343 system($cmd);
344 }
345 print "\n";
346 }
347
348 ############################################################################
349 # DO_MODS
350 ############################################################################
351
352 # Creates the modules.
353 #
354 sub do_mods {
355 print "Modules...\n";
356 my $tzd = Date::Manip::TZdata->new();
357 system("rm -f $mod_dir/*");
358
359 my $zone_list = _yaml_read("tzdata/_zone_list");
360 my %zone_list = %$zone_list;
361 my $num = keys %zone_list;
362 my $len = length($num);
363 my $i = 0;
364
365 my $abbrev = {};
366 my $data = {};
367
368 print " module "," "x($len-length($i)),"$i / $num";
369
370 foreach my $zone (keys %zone_list) {
371 $i++;
372 print "\010"x($len*2+3)," "x($len-length($i)),"$i / $num";
373 my($module,$type,@args) = @{ $zone_list{$zone} };
374
375 if ($type eq "tzdata") {
376 _do_mods_tzdata($tzd,$abbrev,$data,$zone,$module,@args);
377
378 } elsif ($type eq "offset") {
379 _do_mods_offset($tzd,$abbrev,$data,$zone,$module,@args);
380 }
381 }
382 print "\n";
383
384 # $data now contains a hash of:
385 # YEAR => [ TYPE, VAL1, VAL2, ... ]
386 # where TYPE is currently blank.
387 #
388 # VALi is a reference to a time change [ ABB, OFFSET, ISDST ]
389 #
390 # TYPE will be set to one of the following:
391 #
392 # std0, : a standard year is one with two time changes which must
393 # std1 be with ISDST = 1 and 0, and both must be integers
394 # that differ by exactly 1. If the ISDST = 0 comes first,
395 # it is set to std0. Otherwise it is set to std1.
396 # last0,
397 # last1 : if it's a standard year AND the year is after $keep_year
398 # end : a non-standard year after $keep_year
399 # non : a non-standard year before $keep_year
400
401 foreach my $zone (keys %$data) {
402 my $lasttype = '';
403 foreach my $year (keys %{ $$data{$zone} }) {
404 my $type;
405 my @tmp = @{ $$data{$zone}{$year} };
406 shift(@tmp);
407
408 # Standard times must have two changes
409
410 $type = 'std';
411 $type = 'non' if (@tmp != 2);
412
413 # Standard times must have both offsets on the hour.
414
415 my ($off1,$off2);
416 if ($type eq 'std') {
417 $off1 = $tmp[0][1];
418 $off2 = $tmp[1][1];
419 if ($off1 !~ /:00:00$/ ||
420 $off2 !~ /:00:00$/) {
421 $type = 'non';
422 } else {
423 $type = 'std';
424 }
425 }
426
427 # Standard times must have offsets that are 1 hour apart.
428
429 if ($type eq 'std') {
430 $off1 =~ s/:00:00$//;
431 $off2 =~ s/:00:00$//;
432 $type = 'non' if (abs($off1 - $off2) != 1);
433 }
434
435 # Standard times have offsets with two offsets with ISDST = 0 and 1
436
437 my $std;
438 if ($type eq 'std' &&
439 $tmp[0][2] == 1 &&
440 $tmp[1][2] == 0) {
441 $std = 1;
442 } elsif ($type eq 'std' &&
443 $tmp[0][2] == 0 &&
444 $tmp[1][2] == 1) {
445 $std = 0;
446 } else {
447 $type = 'non';
448 }
449
450 # Set the type
451
452 if ($type eq 'std') {
453 if ($year > $keep_year) {
454 $type = "last$std";
455 } else {
456 $type .= $std;
457 }
458
459 } elsif ($year > $keep_year) {
460 $type = 'end';
461 }
462
463 # We'll discard the very last year of a standard timezone
464 # because they end on the first change of a year instead of
465 # the second.
466 next if ($lasttype =~ /last/ && $type eq 'end');
467 $lasttype = $type;
468
469 $$data{$zone}{$year}[0] = $type;
470 }
471 }
472
473 # Create a list of all EST5EDT style time zone aliases.
474 # These only apply during standard years.
475 #
476 # Also, we will ignore aliases when the abbreviations are
477 # offsets.
478
479 my $alias2 = {};
480 ZONE: foreach my $zone (keys %$data) {
481 foreach my $year (sort keys %{ $$data{$zone} }) {
482 my ($type,@tmp) = @{ $$data{$zone}{$year} };
483 next if ($type ne 'std0' &&
484 $type ne 'std1' &&
485 $type ne 'last0' &&
486 $type ne 'last1');
487
488 # The format is
489 # STDABB STDOFFHR DSTABB
490 # where STDABB and DSTABB are the abbreviations, and STDOFFHR
491 # is the offset for standard time as an integer negated.
492
493 my ($stdabb,$dstabb,$stdoff);
494 if ($type eq 'std0' || $type eq 'last0') {
495 $stdabb = $tmp[0][0];
496 $dstabb = $tmp[1][0];
497 $stdoff = $tmp[0][1];
498 } else {
499 $stdabb = $tmp[1][0];
500 $dstabb = $tmp[0][0];
501 $stdoff = $tmp[1][1];
502 }
503 $stdoff =~ s/:00:00$//;
504 $stdoff *= -1;
505
506 next if ($stdabb =~ /^[+-]?\d+$/ ||
507 $dstabb =~ /^[+-]?\d+$/);
508
509 my $alias = "${stdabb}${stdoff}${dstabb}";
510
511 if ($type eq 'last0' || $type eq 'last1') {
512 _do_mods_years($alias2,$zone,$alias,$year,9999);
513 next ZONE;
514 }
515 _do_mods_years($alias2,$zone,$alias,$year,$year);
516 }
517 }
518
519 _yaml_write($data, 'tzdata/_data',0);
520 _yaml_write($alias2,'tzdata/_alias2_un',0);
521
522 $abbrev = _order_elements($abbrev);
523 $alias2 = _order_elements($alias2);
524
525 _yaml_write($abbrev,'tzdata/_abbrev_or',0);
526 _yaml_write($alias2,'tzdata/_alias2_or',0);
527 }
528
529 # This creates a module from a tzdata dump.
530 #
531 sub _do_mods_tzdata {
532 my($tzd,$abbrev,$data,$zone,$module) = @_;
533
534 my @lines = `cat tzdata/dump/$module`;
535 chomp(@lines);
536
537 while (@lines && $lines[0] =~ /NULL$/) {
538 shift(@lines);
539 }
540 while (@lines && $lines[$#lines] =~ /NULL$/) {
541 pop(@lines);
542 }
543
544 if (! @lines) {
545 warn "[_do_mods_tzdata] empty zone [$zone]\n";
546 return;
547 }
548
549 # Check the format of every line
550 my $err = _do_mods_tzdata_check($zone,@lines);
551 return if ($err);
552 _do_mods_tzdata_mod($tzd,$abbrev,$data,$zone,$module,@lines);
553 }
554
555 # This checks every line in a zdump file to make sure it is the
556 # correct format.
557 #
558 sub _do_mods_tzdata_check {
559 my($zone,@lines) = @_;
560 my($dow) = '(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)';
561 my($mon) = '(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)';
562 my($dom) = '(?:\d+)';
563 my($time) = '(?:\d\d:\d\d:\d\d)';
564 my($year) = '(?:\d\d\d\d)';
565 my($drx) = qr/$dow\s+$mon\s+$dom\s+$time\s+$year/;
566 my($rx) = qr/\Q$zone\E\s+$drx\s+UT\s+=\s+$drx\s+\S+\s+isdst=[01]\s+gmtoff=\-?\d+$/;
567
568 my($err) = 0;
569 foreach my $line (@lines) {
570 if ($line !~ /$rx/) {
571 warn "[_do_mods_tzdata] invalid line [$zone]\n $line\n";
572 $err = 1;
573 }
574 }
575 return $err;
576 }
577
578 sub _do_mods_tzdata_mod {
579 my($tzd,$abbrev,$data,$zone,$module,@lines) = @_;
580
581 ###
582 ### Analyze the dump file and store information about all
583 ### time zone periods in a list. A time zone period is a
584 ### starting time and ending time during which the abbreviation,
585 ### offset, and ISDST values remain unchanged.
586 ###
587 ### The first line in the dump file defines when the pre-use
588 ### period (i.e. the period of time before the time zone was
589 ### actually defined) ended.
590 ###
591 ### After the first line, all lines (except the last one) appear as
592 ### pairs. The first one tells the time when a new time zone period
593 ### starts (which should be exactly 1 second after the previous
594 ### period ended) and the second line tells when the period ends.
595 ###
596 ### The last line defines the start of a new period that doesn't
597 ### have an end defined. If the year is after $keep_year, then
598 ### the period switches to LASTRULE handline. If it is before
599 ### $keep_year, then the time zone stopped doing DST changes and
600 ### stay in the same period for good.
601 ###
602
603 #
604 # Parse the first dump line to determine the end of the
605 # pre-zone period.
606 #
607
608 my @dates;
609 my $last = 1; # Whether or not to do LAST RULE
610 my ($year,$year2);
611
612 my $line = shift(@lines);
613 my($dowU,$monU,$domU,$timeU,$yearU,$dowL,$monL,$domL,$timeL,$yearL,
614 $abb,$isdst) = _do_mods_splitdump($line);
615
616 if ($isdst) {
617 warn "[_do_mods_tzdata] first line in DST [$zone]\n";
618 return 1;
619 }
620
621 #
622 # Calculate the offset of the pre-zone period.
623 #
624
625 my @endUT = ($yearU,$monU,$domU,@{ $dmb->split("time",$timeU) });
626 my @endLT = ($yearL,$monL,$domL,@{ $dmb->split("time",$timeL) });
627 my @offset = @{ $dmb->calc_date_date(\@endUT,\@endLT) };
628 my $offset = $dmb->join("offset",\@offset);
629
630 if ($offset eq "" ||
631 $abb eq "" ||
632 $isdst eq "") {
633 warn "[_do_mods_tzdata] blank value in zone [$zone, @endUT]\n";
634 return 1;
635 }
636
637 #
638 # The pre-zone period starts on Jan 2 0001 at 00:00:00 and
639 # ends at the time from the first dump line.
640 #
641
642 my @begUT = @{ $dmb->split("date",$first_date) };
643 my @begLT = @{ $dmb->calc_date_time(\@begUT,\@offset) };
644 @dates = ("0001",[@begUT],[@begLT],$offset,[@offset],
645 $abb,$isdst,[@endUT],[@endLT]);
646
647 $year2 = $endUT[0];
648 _do_mods_years($abbrev,$zone,$abb,"0001",$year2) if ($abb !~ /^[+-]?\d*$/);
649 $$data{$zone}{"0001"} = [ '', [$abb,$offset,$isdst] ];
650
651 #
652 # Parse every pair of dump lines.
653 #
654
655 while (@lines) {
656
657 #
658 # The first line is the start of the period
659 #
660
661 $line = shift(@lines);
662 ($dowU,$monU,$domU,$timeU,$yearU,$dowL,$monL,$domL,$timeL,$yearL,
663 $abb,$isdst) = _do_mods_splitdump($line);
664 $year = $yearU;
665
666 @begUT = ($yearU,$monU,$domU,@{ $dmb->split("time",$timeU) });
667 @begLT = ($yearL,$monL,$domL,@{ $dmb->split("time",$timeL) });
668
669 my @tmp = @{ $dmb->calc_date_time(\@endUT,[0,0,1]) };
670 if ($dmb->cmp(\@tmp,\@begUT) != 0) {
671 warn "[_do_mods_tzdata] invalid start in zone [$zone, @begUT]\n";
672 return 1;
673 }
674
675 @offset = @{ $dmb->calc_date_date(\@begUT,\@begLT) };
676 $offset = $dmb->join("offset",\@offset);
677
678 if ($offset eq "" ||
679 $abb eq "" ||
680 $isdst eq "") {
681 warn "[_do_mods_tzdata] blank value in zone [$zone, @begUT]\n";
682 return 1;
683 }
684
685 #
686 # If a second line exists, it is the end of the period.
687 #
688 # If no second line exists, then either we need to switch to
689 # LAST RULE behavior (if the year of the first line is after
690 # $keep_year), or the zone abandoned doing daylight savings
691 # time and this line reflects the time until 9999.
692 #
693
694 if (@lines) {
695
696 # A second line marks the end of the period
697
698 my ($a,$i);
699 $line = shift(@lines);
700 ($dowU,$monU,$domU,$timeU,$yearU,$dowL,$monL,$domL,$timeL,$yearL,
701 $a,$i) = _do_mods_splitdump($line);
702
703 @endUT = ($yearU,$monU,$domU,@{ $dmb->split("time",$timeU) });
704 @endLT = ($yearL,$monL,$domL,@{ $dmb->split("time",$timeL) });
705
706 my @o = @{ $dmb->calc_date_date(\@endUT,\@endLT) };
707 my $o = $dmb->join("offset",\@o);
708
709 if ($o eq "" ||
710 $a eq "" ||
711 $i eq "") {
712 warn "[_do_mods_tzdata] blank value in zone [$zone, @endUT]\n";
713 return 1;
714 }
715
716 if ($o ne $offset ||
717 $a ne $abb ||
718 $i ne $isdst) {
719 warn "[_do_mods_tzdata] invalid value in zone [$zone, @endUT]\n";
720 return 1;
721 }
722
723 } elsif ($year > $keep_year &&
724 ! exists $no_last{$zone}) {
725
726 # If it's a single line after $keep_year, then it's the start
727 # of a regular LAST RULE style time change. Discard it... we'll
728 # use the LAST RULE to come up with those periods.
729
730 last;
731
732 } else {
733
734 # A single line before $keep_year means that the time zone
735 # stopped doing DST stuff, and switched to a single offset.
736 # There is no LAST RULE in this case.
737 #
738 # This will also apply to zones which do not use the LAST
739 # RULE method.
740
741 @endUT = @{ $dmb->split("date",$last_date) };
742 @endLT = @{ $dmb->calc_date_time(\@endUT,\@offset) };
743 $last = 0;
744 }
745
746 # Now store the data for this time zone period
747
748 push(@dates,$year,[@begUT],[@begLT],$offset,[@offset],$abb,$isdst,[@endUT],[@endLT]);
749 $year2 = $endUT[0];
750
751 if (exists $$data{$zone}{$year}) {
752 push(@{ $$data{$zone}{$year} },[$abb,$offset,$isdst]);
753 } else {
754 $$data{$zone}{$year} = [ '', [$abb,$offset,$isdst] ];
755 }
756
757 _do_mods_years($abbrev,$zone,$abb,$year,$year2) if ($abb !~ /^[+-]?\d*$/);
758 }
759
760 ###
761 ### Now we'll analyze all the critical dates. Three different things
762 ### will occur:
763 ###
764 ### 1) For years < $keep_year, the data will simply get stored in
765 ### the module.
766 ### 2) For year = $keep_year, the data will be stored in the module
767 ### and used to determine how LAST RULE critical dates are
768 ### determined.
769 ### 3) For year > $keep_year, critical dates will not be stored, but
770 ### will be tested to make sure they are consistant with the methods
771 ### determined in 2). However, this step will be elsewhere. I will
772 ### use a dump script to create actual dumps and compare them to
773 ### the standard tzcode dump.
774 ###
775
776 my @mod; # data to store in the module
777 my %last; # LAST RULE description
778 my @mon;
779
780 if ($last) {
781 %last = _do_mods_lastrule($tzd,$zone);
782 @mon = sort keys %{ $last{"rules"} };
783 }
784
785 foreach my $mon (@mon) {
786 if ($mon == 1 || $mon == 12) {
787 # If a change ever happens in Jan/Dec in the LAST RULE, we
788 # may need to make sure that the year won't change (it would
789 # be horrible if it did).
790 warn "[_do_mods_tzdata] LAST RULE in Jan/Dec [$zone, $mon]\n";
791 }
792 }
793
794 my $didlast = 0;
795 my($begUT,$begLT,$endUT,$endLT,$offsetref);
796 while (@dates) {
797 ($year,$begUT,$begLT,$offset,$offsetref,$abb,$isdst,$endUT,$endLT,@dates) = @dates;
798 @offset = @$offsetref;
799
800 if ($year <= $keep_year || ! $last) {
801
802 #
803 # Store critical dates from dump files for years <= $keep_year
804 #
805
806 push(@mod,$year,$begUT,$begLT,$offset,$offsetref,$abb,$isdst,$endUT,$endLT);
807
808 if ($year == $keep_year && $last) {
809
810 my $mon = shift(@mon);
811 return 1 if (! $mon);
812
813 if ($isdst != $last{"rules"}{$mon}{"isdst"}) {
814 warn "[_do_mods_tzdata] isdst mismatch in LAST RULE " .
815 "[$zone, $mon]\n";
816 return 1;
817 }
818 if ($offset ne
819 $last{"zone"}{ ($isdst ? "dstoff" : "stdoff") }) {
820 warn "[_do_mods_tzdata] offset mismatch in LAST RULE " .
821 "[$zone, $mon]\n";
822 return 1;
823 }
824
825 $last{"rules"}{$mon}{"abb"} = $abb;
826 _do_mods_years($abbrev,$zone,$abb,$keep_year+1,9999)
827 if ($abb !~ /^[+-]?\d*$/);
828 $didlast++;
829 }
830 }
831 }
832
833 if ($last && $didlast != 2) {
834 warn "[_do_mods_tzdata] LAST RULE incomplete [$zone]\n";
835 return 1;
836 }
837
838 _do_mods_write($zone,$module,[@mod],%last);
839 }
840
841 # This returns a hash of information concerning "last rules". This
842 # information will allow us to calculate critical dates in future
843 # years.
844 #
845 # Information consists of:
846 # flag,dow,num : See TZdata.pm (used to calculate a DoM)
847 # add : Some of the DoM calculations do not
848 # return the final DoM after offsets have
849 # been applied. If this is +1, it'll add
850 # a day. If it's -1, it'll subtract a day.
851 # time,abb,offset : Information that should be constant.
852 # dst : Whether it is a change to DST or not.
853 #
854 sub _do_mods_lastrule {
855 my($tzd,$zone) = @_;
856
857 # Get the rule dates that apply to $keep_year
858
859 my @rules = $tzd->_zoneInfo($zone,"rules",$keep_year);
860 my @r;
861 while (@rules) {
862 my $rule = shift(@rules);
863 my $type = shift(@rules);
864
865 # All LAST RULES are currently of type TZ_RULE . If this
866 # ever changes, we'll have to add support.
867 if ($type != $Date::Manip::TZdata::TZ_RULE) {
868 warn "[_do_mods_lastrule] unsupported rule type [$zone]\n";
869 return "";
870 }
871
872 push(@r,$tzd->_ruleInfo($rule,"rules",$keep_year));
873 }
874
875 # Make sure that there are exactly two rules. If there are
876 # not, we'll need to add support.
877
878 if ($#r != 1) {
879 warn "[_do_mods_lastrule] two rules required [$zone]\n";
880 return "";
881 }
882
883 # Also get the zone line that applies. There must be one or
884 # we'll need to add support.
885
886 my @zone = $tzd->_zoneInfo($zone,"zonelines",$keep_year);
887 if ($#zone != 0) {
888 warn "[_do_mods_lastrule] one zone line required [$zone]\n";
889 return "";
890 }
891
892 # Analyze the rules/zone to get the "last rule" (i.e. information
893 # that can be used to calculate critical dates in future years).
894 #
895 # Some additional information will be added once dump lines are
896 # analyzed.
897
898 my %last = ( "year" => $keep_year + 1,
899 "zone" => { "stdoff" => $dmb->_delta_convert("offset",$zone[0][0]),
900 "dstoff" => '' },
901 "rules" => {},
902 );
903
904 my $totdst = 0;
905 my $totst = 0;
906 foreach my $rule (@r) {
907 my($y0,$y1,$ytype,$mon,$flag,$dow,$num,$timetype,$time,$offset,
908 $lett) = @$rule;
909 my $isdst = ($offset eq "00:00:00" ? 0 : 1);
910 $totdst += $isdst;
911 $totst += (1-$isdst);
912
913 if ($isdst) {
914 my $dstoff = $dmb->calc_time_time( $dmb->split("time",$last{"zone"}{"stdoff"}),
915 $dmb->split("time",$offset));
916 $dstoff = $dmb->join("offset",$dstoff);
917 $last{"zone"}{"dstoff"} = $dstoff;
918 }
919
920 $mon="0$mon" if (length($mon) != 2);
921
922 $last{"rules"}{$mon} = { "flag" => $flag,
923 "dow" => $dow,
924 "num" => $num,
925 "type" => $timetype,
926 "time" => $time,
927 "isdst" => $isdst,
928 "abb" => "",
929 };
930 }
931
932 # One rule must be standard time, one must be daylight savings time.
933 # If this is not the case, we'll have to add support.
934
935 if (exists $last_zone_offsets{$zone}) {
936 if (! $last{"zone"}{"dstoff"}) {
937 $last{"zone"}{"dstoff"} = $last{"zone"}{"stdoff"};
938 }
939
940 my $expdst = $last_zone_offsets{$zone}{"dst"};
941 my $expst = $last_zone_offsets{$zone}{"st"};
942 if ($totdst != $expdst ||
943 $totst != $expst) {
944 warn "\n" .
945 "[_do_mods_lastrule] wrong number of DST/STD offsets\n" .
946 " [exp $expdst/$expst got $totdst/$totst] [$zone]\n";
947 return "";
948 }
949
950 } elsif ($totdst != 1 || $totst != 1) {
951 warn "[_do_mods_lastrule] 1 DST and 1 STD rule required [$zone]\n";
952 return "";
953 }
954
955 return %last;
956 }
957
958 # Split a dump line and return the values.
959 #
960 sub _do_mods_splitdump {
961 my($line) = @_;
962 my(%mon) = qw(Jan 01 Feb 02 Mar 03 Apr 04 May 05 Jun 06
963 Jul 07 Aug 08 Sep 09 Oct 10 Nov 11 Dec 12);
964 my(%dow) = qw(Mon 1 Tue 2 Wed 3 Thu 4 Fri 5 Sat 6 Sun 7);
965
966 my($z,$dowU,$monU,$domU,$timeU,$yearU,$utc,$equal,
967 $dowW,$monW,$domW,$timeW,$yearW,$abb,$isdst) = split(/\s+/,$line);
968 $isdst =~ s/isdst=//;
969
970 $monU = $mon{$monU} if (exists $mon{$monU});
971 $monW = $mon{$monW} if (exists $mon{$monW});
972 $monU = "0$monU" if (length($monU) != 2);
973 $monW = "0$monW" if (length($monW) != 2);
974
975 $dowU = $dow{$dowU} if (exists $dow{$dowU});
976 $dowU = $dow{$dowW} if (exists $dow{$dowW});
977
978 $domU = "0$domU" if (length($domU) != 2);
979 $domW = "0$domW" if (length($domW) != 2);
980
981 return ($dowU,$monU,$domU,$timeU,$yearU,$dowW,$monW,$domW,$timeW,$yearW,
982 $abb,$isdst);
983 }
984
985 # This records an element as having been used in a given year.
986 #
987 sub _do_mods_years {
988 my($hash,$zone,$ele,$year,$year2) = @_;
989
990 if (exists $$hash{$ele}{$zone}) {
991 $$hash{$ele}{$zone}[1] = $year2;
992
993 } else {
994 $$hash{$ele}{$zone} = [$year,$year2];
995 }
996 }
997
998 # This creates a module from an offset.
999 #
1000 sub _do_mods_offset {
1001 my($tzd,$abbrev,$data,$zone,$module,$offset) = @_;
1002
1003 my($abb) = $zone;
1004 $abb =~ s/Etc\///;
1005 _do_mods_years($abbrev,$zone,$abb,"0001","9999");
1006
1007 $offset = $dmb->_delta_convert("offset",$offset);
1008 my @offset = @{ $dmb->split("offset",$offset) };
1009
1010 my @begUT = @{ $dmb->split("date",$first_date) };
1011 my @begLT = @{ $dmb->calc_date_time(\@begUT,\@offset) };
1012
1013 my @endUT = @{ $dmb->split("date",$last_date) };
1014 my @endLT = @{ $dmb->calc_date_time(\@endUT,\@offset) };
1015
1016 _do_mods_write($zone,$module,
1017 ["0001",[@begUT],[@begLT],$offset,[@offset],$abb,0,
1018 [@endUT],[@endLT]],
1019 ());
1020 $$data{$zone}{"0001"} = [ '', [$abb,$offset,0] ];
1021 }
1022
1023 sub _do_mods_write {
1024 my($zone,$module,$dates,%last) = @_;
1025
1026 # Store the critical dates in the module
1027
1028 my @tmp = `cat tzdata/_version`;
1029 chomp(@tmp);
1030 my $tzdata_vers = "tzdata" . $tmp[0];
1031 my $tzcode_vers = "tzcode" . $tmp[1];
1032 my $timestamp = `date`;
1033 chomp($timestamp);
1034
1035 my $out = new IO::File;
1036 $out->open(">$mod_dir/$module.pm");
1037 print $out "package #
1038 Date::Manip::TZ::$module;
1039 # Copyright (c) 2008-$curr_year Sullivan Beck. All rights reserved.
1040 # This program is free software; you can redistribute it and/or modify it
1041 # under the same terms as Perl itself.
1042
1043 # This file was automatically generated. Any changes to this file will
1044 # be lost the next time 'tzdata' is run.
1045 # Generated on: $timestamp
1046 # Data version: $tzdata_vers
1047 # Code version: $tzcode_vers
1048
1049 # This module contains data from the zoneinfo time zone database. The original
1050 # data was obtained from the URL:
1051 # ftp://$tzdata_src/$tzdata_dir
1052
1053 use strict;
1054 use warnings;
1055 require 5.010000;
1056
1057 our (\%Dates,\%LastRule);
1058 END {
1059 undef \%Dates;
1060 undef \%LastRule;
1061 }
1062
1063 our (\$VERSION);
1064 \$VERSION='$VERSION';
1065 END { undef \$VERSION; }
1066
1067 \%Dates = (
1068 ";
1069
1070 my @dates = @$dates;
1071 my $lastyear = 0;
1072 my ($year,$begUT,$begLT,$offset,$offsetref,$abb,$isdst,$endUT,$endLT);
1073
1074 while (@dates) {
1075 ($year,$begUT,$begLT,$offset,$offsetref,$abb,$isdst,$endUT,$endLT,@dates) =
1076 @dates;
1077 $year += 0;
1078 my $yrprt = $year . " "x(4-length($year));
1079 if ($year != $lastyear) {
1080 if ($lastyear) {
1081 print $out " ],\n";
1082 }
1083 print $out " $yrprt =>\n";
1084 print $out " [\n";
1085 $lastyear = $year;
1086 }
1087 my $begUTs = $dmb->join("date",$begUT);
1088 my $begLTs = $dmb->join("date",$begLT);
1089 my $endUTs = $dmb->join("date",$endUT);
1090 my $endLTs = $dmb->join("date",$endLT);
1091 $begUT = join(",",map { $_+0 } @$begUT);
1092 $begLT = join(",",map { $_+0 } @$begLT);
1093 $endUT = join(",",map { $_+0 } @$endUT);
1094 $endLT = join(",",map { $_+0 } @$endLT);
1095 $offsetref = join(",",map { $_+0 } @$offsetref);
1096
1097 print $out " [ [$begUT],[$begLT],'$offset',[$offsetref],\n";
1098 print $out " '$abb',$isdst,[$endUT],[$endLT],\n";
1099 print $out " '$begUTs','$begLTs','$endUTs','$endLTs' ],\n";
1100 }
1101
1102 print $out " ],\n";
1103
1104 print $out ");
1105
1106 \%LastRule = (
1107 ";
1108
1109 if (exists $last{"year"}) {
1110 print $out " 'zone' => {\n";
1111 foreach my $key (sort keys %{ $last{"zone"} }) {
1112 my $val = $last{"zone"}{$key};
1113 print $out " "x16,"'$key' => '$val',\n";
1114 }
1115
1116 print $out " },
1117 'rules' => {\n";
1118
1119 foreach my $mon (sort keys %{ $last{"rules"} }) {
1120 print $out " "x16,"'$mon' => {\n";
1121 my $flag = $last{"rules"}{$mon}{"flag"};
1122 if ($flag == $Date::Manip::TZdata::TZ_DOM) {
1123 $flag = "dom";
1124
1125 } elsif ($flag == $Date::Manip::TZdata::TZ_LAST) {
1126 $flag = "last";
1127
1128 } elsif ($flag == $Date::Manip::TZdata::TZ_GE) {
1129 $flag = "ge";
1130
1131 } elsif ($flag == $Date::Manip::TZdata::TZ_LE) {
1132 $flag = "le";
1133 }
1134 $last{"rules"}{$mon}{"flag"} = $flag;
1135
1136 foreach my $key (qw(flag dow num type time isdst abb)) {
1137 print $out " "x25,"'$key'", " "x(7-length($key))," => '",
1138 $last{"rules"}{$mon}{$key},"',\n";
1139 }
1140 print $out " "x24,"},\n";
1141 }
1142
1143 print $out " },\n";
1144 }
1145
1146 print $out ");
1147
1148 1;
1149 ";
1150
1151 $out->close;
1152 }
1153
1154 ############################################################################
1155 # DO_OFF
1156 ############################################################################
1157
1158 sub do_off {
1159 print "Offset modules...\n";
1160
1161 my $data = _yaml_read("tzdata/_data");
1162
1163 # Get a list of all zones which an offset appears in, and the year
1164 # range of the offset.
1165
1166 my %offset_un = ( 0 => {}, 1 => {} );
1167
1168 ZONE:foreach my $zone (keys %$data) {
1169 my $lastoffset = '';
1170 my $lastisdst = '';
1171 my @year = sort keys %{ $$data{$zone} };
1172 while (@year) {
1173 my $year = shift(@year);
1174
1175 # The offset at the end of the previous year is still in
1176 # affect.
1177
1178 if ($lastoffset) {
1179 _do_mods_years($offset_un{$lastisdst},$zone,$lastoffset,$year,$year);
1180 }
1181
1182 my ($type,@tmp) = @{ $$data{$zone}{$year} };
1183
1184 foreach my $tmp (@tmp) {
1185 my($abb,$offset,$isdst) = @$tmp;
1186 $lastoffset = $offset;
1187 $lastisdst = $isdst;
1188
1189 if ($type =~ /last/) {
1190 _do_mods_years($offset_un{$isdst},$zone,$offset,$year,9999);
1191 } else {
1192 _do_mods_years($offset_un{$isdst},$zone,$offset,$year,$year);
1193 }
1194 }
1195
1196 next ZONE if ($type =~ /last/);
1197 _do_mods_years($offset_un{$lastisdst},$zone,$lastoffset,$year,9999)
1198 if (! @year);
1199 }
1200 }
1201
1202 # Convert %offset to a couple other formats that will be useful.
1203
1204 my %offset_or;
1205 $offset_or{0} = _order_elements($offset_un{0});
1206 $offset_or{1} = _order_elements($offset_un{1});
1207
1208 my %offset2_or;
1209 foreach my $isdst (keys %offset_un) {
1210 foreach my $offset (keys %{ $offset_un{$isdst} }) {
1211 $offset2_or{$offset}{$isdst} = $offset_or{$isdst}{$offset};
1212 }
1213 }
1214
1215 # Come up with a module name for each offset.
1216
1217 my %offmod;
1218 my $o = "000";
1219 foreach my $offset (sort keys %offset2_or) {
1220 my $offmod = "off$o";
1221 $offmod{$offset} = $offmod;
1222 $o++;
1223 }
1224
1225 # Write out each module
1226
1227 my $num = keys %offmod;
1228 my $len = length($num);
1229 my $i = 0;
1230
1231 print " module "," "x($len-length($i)),"$i / $num";
1232
1233 _warn_changes($offset_or{0},$def_off{0},15,12,33,"0");
1234 _warn_changes($offset_or{1},$def_off{1},15,12,33,"1");
1235
1236 system("rm -f $off_dir/*");
1237 foreach my $offset (sort keys %offset2_or) {
1238 $i++;
1239 print "\010"x($len*2+3)," "x($len-length($i)),"$i / $num";
1240
1241 my $offmod = $offmod{$offset};
1242 _do_off($offset,$offmod,\%offset_or);
1243 }
1244 print "\n";
1245
1246 _yaml_write(\%offmod,"tzdata/_offmod",0);
1247 _yaml_write(\%offset_un,"tzdata/_offset_un",0);
1248 _yaml_write(\%offset_or,"tzdata/_offset_or",0);
1249 _yaml_write(\%offset2_or,"tzdata/_offset2_or",0);
1250 }
1251
1252 sub _do_off {
1253 my($offset,$module,$offset_or) = @_;
1254
1255 my @tmp = `cat tzdata/_version`;
1256 chomp(@tmp);
1257 my $tzdata_vers = "tzdata" . $tmp[0];
1258 my $tzcode_vers = "tzcode" . $tmp[1];
1259 my $timestamp = `date`;
1260 chomp($timestamp);
1261
1262 my $out = new IO::File;
1263 my $mod = "Date::Manip::Offset::$module";
1264 $out->open(">$off_dir/$module.pm");
1265 print $out "package #
1266 Date::Manip::Offset::$module;
1267 # Copyright (c) 2008-$curr_year Sullivan Beck. All rights reserved.
1268 # This program is free software; you can redistribute it and/or modify it
1269 # under the same terms as Perl itself.
1270
1271 # This file was automatically generated. Any changes to this file will
1272 # be lost the next time 'tzdata' is run.
1273 # Generated on: $timestamp
1274 # Data version: $tzdata_vers
1275 # Code version: $tzcode_vers
1276
1277 # This module contains data from the zoneinfo time zone database. The original
1278 # data was obtained from the URL:
1279 # ftp://$tzdata_src/$tzdata_dir
1280
1281 use strict;
1282 use warnings;
1283 require 5.010000;
1284
1285 our (\$VERSION);
1286 \$VERSION='$VERSION';
1287 END { undef \$VERSION; }
1288
1289 our (\$Offset,\%Offset);
1290 END {
1291 undef \$Offset;
1292 undef \%Offset;
1293 }
1294
1295 \$Offset = '$offset';
1296
1297 \%Offset = (
1298 ";
1299
1300 foreach my $isdst (sort keys %$offset_or) {
1301 next if (! exists $$offset_or{$isdst}{$offset});
1302 my @tmp = @{ $$offset_or{$isdst}{$offset} };
1303
1304 print $out " "x3,$isdst," => [\n";
1305 while (@tmp) {
1306 my $zone = shift(@tmp);
1307 my $year1 = shift(@tmp);
1308 my $year2 = shift(@tmp);
1309 $zone = lc($zone);
1310 print $out " "x6,"'$zone',\n";
1311 }
1312 print $out " "x6,"],\n";
1313 }
1314
1315 print $out ");
1316
1317 1;
1318 ";
1319
1320 $out->close;
1321 }
1322
1323 ############################################################################
1324 # DO_ZONES
1325 ############################################################################
1326
1327 sub do_zones {
1328 print "Zones module...\n";
1329
1330 my @tmp = `cat tzdata/_version`;
1331 chomp(@tmp);
1332 my $tzdata_vers = "tzdata" . $tmp[0];
1333 my $tzcode_vers = "tzcode" . $tmp[1];
1334 my $timestamp = `date`;
1335 chomp($timestamp);
1336
1337 my $zone_list = _yaml_read("tzdata/_zone_list");
1338 my $alias_list = _yaml_read("tzdata/_alias_list");
1339 my $offset2_or = _yaml_read("tzdata/_offset2_or");
1340
1341 my $out = new IO::File;
1342 $out->open(">$zones_pm");
1343 my $pod = new IO::File;
1344 $pod->open(">$zones_pod");
1345
1346 print $out "package Date::Manip::Zones;
1347 # Copyright (c) 2008-$curr_year Sullivan Beck. All rights reserved.
1348 # This program is free software; you can redistribute it and/or modify it
1349 # under the same terms as Perl itself.
1350
1351 # This file was automatically generated. Any changes to this file will
1352 # be lost the next time 'tzdata' is run.
1353 # Generated on: $timestamp
1354 # Data version: $tzdata_vers
1355 # Code version: $tzcode_vers
1356
1357 # This module contains data from the zoneinfo time zone database. The original
1358 # data was obtained from the URL:
1359 # ftp://$tzdata_src/$tzdata_dir
1360
1361 use strict;
1362 use warnings;
1363 require 5.010000;
1364
1365 our (\$VERSION);
1366 \$VERSION='$VERSION';
1367 END { undef \$VERSION; }
1368
1369 our (\$TzdataVersion,\$TzcodeVersion,
1370 \$FirstDate,\$LastDate,\$LastYear,
1371 \%Module,\%ZoneNames,\%Alias,\%Abbrev,\%Offmod);
1372 END {
1373 undef \$TzdataVersion;
1374 undef \$TzcodeVersion;
1375 undef \$FirstDate;
1376 undef \$LastDate;
1377 undef \$LastYear;
1378 undef \%Module;
1379 undef \%ZoneNames;
1380 undef \%Alias;
1381 undef \%Abbrev;
1382 undef \%Offmod;
1383 }
1384
1385 \$TzdataVersion = '$tzdata_vers';
1386 \$TzcodeVersion = '$tzcode_vers';
1387 \$FirstDate = '$first_date';
1388 \$LastDate = '$last_date';
1389 \$LastYear = '$keep_year';
1390
1391 ";
1392
1393 print $pod "
1394 # Copyright (c) 2008-$curr_year Sullivan Beck. All rights reserved.
1395 # This program is free software; you can redistribute it and/or modify it
1396 # under the same terms as Perl itself.
1397
1398 # This file was automatically generated. Any changes to this file will
1399 # be lost the next time 'tzdata' is run.
1400 # Generated on: $timestamp
1401 # Data version: $tzdata_vers
1402 # Code version: $tzcode_vers
1403
1404 # This module contains data from the zoneinfo time zone database. The original
1405 # data was obtained from the URL:
1406 # ftp://$tzdata_src/$tzdata_dir
1407
1408 $podstr
1409
1410 $hdstr NAME
1411
1412 Date::Manip::Zones - Time zone information
1413
1414 $hdstr DESCRIPTION
1415
1416 This module is automatically generated. It contains a complete list of
1417 time zones specified in the standard zoneinfo (or Olson) databases
1418 obtained from:
1419
1420 L<ftp://$tzdata_src/$tzdata_dir/tzdata_vers.tar.gz>
1421
1422 All information is stored in variables, so this module provide no
1423 routines for dealing with time zone information. For routines related
1424 to time zones, see the documentation for the L<Date::Manip::TZ> module.
1425
1426 ";
1427
1428 _do_zones_zones($out,$pod,$zone_list);
1429 _do_zones_names($out,$zone_list);
1430 _do_zones_aliases($out,$pod,$zone_list,$alias_list);
1431 _do_zones_defaults($out,$pod,$offset2_or);
1432 _do_zones_abbrevs($out,$pod);
1433 _do_zones_offsets($out,$pod);
1434
1435 print $out "
1436 1;
1437 ";
1438
1439 $out->close;
1440
1441 print $pod "
1442 $hdstr KNOWN BUGS
1443
1444 None known.
1445
1446 $hdstr BUGS AND QUESTIONS
1447
1448 Please refer to the L<Date::Manip::Problems> documentation for
1449 information on submitting bug reports or questions to the author.
1450
1451 $hdstr SEE ALSO
1452
1453 L<Date::Manip> - main module documentation
1454
1455 $hdstr LICENSE
1456
1457 This script is free software; you can redistribute it and/or
1458 modify it under the same terms as Perl itself.
1459
1460 $hdstr AUTHOR
1461
1462 Sullivan Beck (sbeck\@cpan.org)
1463
1464 =cut
1465 ";
1466
1467 }
1468
1469 sub _do_zones_zones {
1470 my($out,$pod,$zone_list) = @_;
1471
1472 print $out "
1473 \%Module = (
1474 ";
1475
1476 print $pod "
1477 $hdstr TIME ZONES
1478
1479 A description for each time zone from the zoneinfo database is stored
1480 in a separate module. These modules will be loaded automatically as
1481 needed, and are documented here for the sake of completeness.
1482
1483 The modules are available as:
1484
1485 Date::Manip::TZ::_MODULE_
1486
1487 where _MODULE_ is the name of the module for that specific time zone.
1488
1489 The following time zones are derived from the standard zoneinfo
1490 database:
1491
1492 ";
1493
1494 _print_pod_row($pod,1, 5,'TIME ZONE',35, 2,'MODULE NAME',20);
1495
1496 foreach my $zone (sort keys %$zone_list) {
1497 my($mod,$type) = @{ $$zone_list{$zone} };
1498 next if ($type ne "tzdata");
1499
1500 _print_pod_row($pod,0, 5,$zone,35, 2,$mod,0);
1501 _print_mod_row($out, 2,$zone,35,'hashkey', 2,$mod,0,'hashval');
1502 }
1503
1504 print $pod "
1505 The following time zones are NOT derived from the standard zoneinfo
1506 database. They are derived from other standard sources (including
1507 RFC 822):
1508
1509 ";
1510
1511 _print_pod_row($pod,1, 5,'TIME ZONE',35, 2,'MODULE NAME',20);
1512
1513 foreach my $zone (sort keys %$zone_list) {
1514 my($mod,$type) = @{ $$zone_list{$zone} };
1515 next if ($type eq "tzdata");
1516
1517 _print_pod_row($pod,0, 5,$zone,35, 2,$mod,0);
1518 _print_mod_row($out, 2,$zone,35,'hashkey', 2,$mod,0,'hashval');
1519 }
1520
1521 print $out ");
1522 ";
1523 }
1524
1525 sub _do_zones_names {
1526 my($out,$zone_list) = @_;
1527
1528 print $out "
1529 \%ZoneNames = (
1530 ";
1531
1532 foreach my $zone (sort keys %$zone_list) {
1533 my($mod,$type) = @{ $$zone_list{$zone} };
1534 next if ($type ne "tzdata");
1535
1536 _print_mod_row($out, 2,$zone,35,'hashkey', 2,$zone,0,'hashval,nocase');
1537 }
1538
1539 foreach my $zone (sort keys %$zone_list) {
1540 my($mod,$type) = @{ $$zone_list{$zone} };
1541 next if ($type eq "tzdata");
1542
1543 _print_mod_row($out, 2,$zone,35,'hashkey', 2,$zone,0,'hashval,nocase');
1544 }
1545
1546 print $out ");
1547 ";
1548 }
1549
1550 sub _do_zones_aliases {
1551 my($out,$pod,$zone_list,$alias_list) = @_;
1552
1553 my $tzd = Date::Manip::TZdata->new();
1554 my %tzdalias = %{ $$tzd{"alias"} };
1555 my $alias2_un = _yaml_read("tzdata/_alias2_un");
1556 my $alias2_or = _yaml_read("tzdata/_alias2_or");
1557
1558 print $out "
1559 \%Alias = (
1560 ";
1561
1562 # Print out the standard 'zone => zone' aliases
1563
1564 foreach my $zone (sort keys %$zone_list) {
1565 _print_mod_row($out, 2,$zone,35,'hashkey', 2,$zone,0,'hashval');
1566 }
1567
1568 # Print out alternate time zone names from tzdata files
1569
1570 print $pod "
1571 $hdstr TIME ZONE NAMES, ALIASES, AND ABBREVIATIONS
1572
1573 Time zones may be referred to as their full name
1574 (e.g. America/New_York), but there are also a number of standard
1575 aliases and abbreviations that may be used.
1576
1577 Standard aliases are listed below. Additional aliases can be created,
1578 or existing aliases overridden using the C<new_alias> method of the
1579 L<Date::Manip::TZ> module.
1580
1581 The zoneinfo database provides several standard aliases, including:
1582
1583 ";
1584
1585 _print_pod_row($pod,1, 5,'ALTERNATE NAME',35, 2,'TIME ZONE',20);
1586
1587 foreach my $alias (sort keys %tzdalias) {
1588 my $zone = $tzdalias{$alias};
1589
1590 # Don't duplicate the 'zone => zone' or 'EST5EDT => zone' aliases
1591 next if (exists $$zone_list{$zone} && $alias eq $zone);
1592 next if (exists $$alias_list{$zone} && $$alias_list{$zone}[1] ne "tzdata");
1593 next if (exists $$alias2_un{$zone});
1594
1595 _print_pod_row($pod,0, 5,$alias,35, 2,$zone,0);
1596 _print_mod_row($out, 2,$alias,35,'hashkey', 2,$zone,0,'hashval');
1597 }
1598
1599 # Do the EST5EDT style aliases
1600
1601 print $pod "
1602 There are a large number of possible time zone aliases of the form
1603 EST5EDT. The main 4 used in the United States are CST6CDT, EST5EDT,
1604 MST7MDT, and PST8PDT and these are specifically called for in RFC 822,
1605 so whenever possible, these will refer to the US time zones, but some
1606 aliases may possibly refer to more than one time zone. In these
1607 instances, I have selected one of them to be the default time zone to
1608 use (based on how recently it was used, and for what period of
1609 time). In the list below, all possible time zones are listed for each
1610 alias. The first time zone listed is the one used by default. The
1611 default alias can be overridden as described above.
1612
1613 ";
1614
1615 _print_pod_row($pod,1, 5,'ALTERNATE NAME',35, 2,'TIME ZONE',20);
1616
1617 _warn_changes($alias2_or,\%def_alias2,3,16,42);
1618
1619 foreach my $ele (sort keys %$alias2_or) {
1620 my @tmp = @{ $$alias2_or{$ele} };
1621 my $first = $ele;
1622 while (@tmp) {
1623 my $alias = shift(@tmp);
1624 my $year1 = shift(@tmp);
1625 my $year2 = shift(@tmp);
1626 _print_pod_row($pod,0, 5,$first,35, 2,$alias,0);
1627 _print_mod_row($out, 2,$first,35,'hashkey', 2,$alias,0,'hashval') if ($first);
1628 $first = '';
1629 }
1630 }
1631
1632 # Print out alternate time zone names other sources
1633
1634 print $pod "
1635 There are also a number of standard aliases. Some of these are
1636 included to fix minor issues with the tzdata files. Others come from
1637 standard sources including RFC 822 or the list of time zone names used
1638 on Microsoft Windows operating systems.
1639
1640 Aliases include:
1641
1642 ";
1643
1644 _print_pod_row($pod,1, 5,'ALTERNATE NAME',35, 2,'TIME ZONE',20);
1645
1646 foreach my $alias (sort keys %$alias_list) {
1647 my($zone,$type) = @{ $$alias_list{$alias} };
1648 next if ($type eq "tzdata" || $type eq "ignore");
1649
1650 # Don't duplicate the 'zone => zone' aliases
1651 next if (exists $$zone_list{$zone} && $alias eq $zone);
1652
1653 _print_pod_row($pod,0, 5,$alias,35, 2,$zone,0);
1654 _print_mod_row($out, 2,$alias,35,'hashkey', 2,$zone,0,'hashval');
1655 }
1656
1657 print $out ");
1658 ";
1659 }
1660
1661 sub _do_zones_defaults {
1662 my($out,$pod,$offset2_or) = @_;
1663
1664 # Start the defaults (POD only)
1665
1666 print $pod "
1667 Periodically, we need to be able to determine a time zone based on an
1668 offset. In addition, the ISDST may be known, and a date/time may be
1669 available. The following table shows what time zones are examined based
1670 on the offset, and in what order. The first match is used. If the
1671 ISDST time is not known, the standard zones will be tested followed by
1672 the DST zones.
1673
1674 The default order can be overridden with the C<off_zones> method in the
1675 L<Date::Manip::TZ> module.
1676
1677 ";
1678
1679 _print_pod_row($pod,1, 5,'ISDST',5, 2,'OFFSET',10, 2,'TIME ZONE',25);
1680
1681 foreach my $isdst (0,1) {
1682
1683 foreach my $off (sort { _cmp_zoneoffsets($a,$b) } keys %$offset2_or) {
1684 next unless (exists $$offset2_or{$off}{$isdst});
1685 my @tmp = @{ $$offset2_or{$off}{$isdst} };
1686 my $zone = shift(@tmp);
1687 my $year1= shift(@tmp);
1688 my $year2= shift(@tmp);
1689
1690 my $dst = $isdst;
1691
1692 _print_pod_row($pod,0, 5,$dst,5, 2,$off,10, 2,$zone,0);
1693
1694 $off = "";
1695 $dst = " ";
1696 while (@tmp) {
1697 $zone = shift(@tmp);
1698 $year1 = shift(@tmp);
1699 $year2 = shift(@tmp);
1700
1701 _print_pod_row($pod,0, 5,$dst,5, 2,$off,10, 2,$zone,0);
1702 }
1703 }
1704 print $pod "\n";
1705 }
1706 }
1707
1708 sub _cmp_zoneoffsets {
1709 my($x,$y) = @_;
1710
1711 # A negative offset comes before a positive one
1712
1713 if ($x =~ /^-/ && $y =~ /^\+/) {
1714 return -1;
1715 } elsif ($y =~ /^-/ && $x =~ /^\+/) {
1716 return +1;
1717 }
1718
1719 # Netgative offsets are sorted reverse.
1720
1721 if ($x =~ /^-/) {
1722 return ($y cmp $x);
1723 }
1724
1725 # Positive offsets are sorted normally.
1726
1727 return ($x cmp $y);
1728 }
1729
1730 sub _do_zones_abbrevs {
1731 my($out,$pod) = @_;
1732
1733 my $abbrev_or = _yaml_read("tzdata/_abbrev_or");
1734
1735 # Start the aliases output (both POD and module)
1736
1737 print $out "
1738 \%Abbrev = (
1739 ";
1740
1741 # Print out EST => ZONE aliases for abbreviations which only occur
1742 # in a single zone.
1743
1744 delete $$abbrev_or{'LMT'};
1745 delete $$abbrev_or{'zzz'};
1746
1747 # Print out EST => ZONE aliases
1748
1749 print $pod "
1750 In the time zone definitions, abbreviations are used to specify the
1751 current time (e.g. EST in the America/New_York time zone). In some
1752 cases, the abbreviation appears in only a single time zone, so for
1753 these, there is no ambiguity.
1754
1755 More often though, abbreviations are used in multiple time zones. When
1756 a date is parsed that contains one of these abbreviations, it will try
1757 to interpret the date using each of the time zones in the order listed
1758 below until one is found which yields a valid date.
1759
1760 The abbreviations LMT and zzz which occur in the zoneinfo databases
1761 are ignored (and when parsing a date including them, the local time
1762 zone will be used).
1763
1764 The default order can be overridden using the C<abbrev> method of the
1765 L<Date::Manip::TZ> module.
1766
1767 The order given here is open to discussion (and possible change) based
1768 on changes to the timezone database. I will always place emphasis on a
1769 time zone that used the abbreviation more recently than another time zone.
1770 Within those constraints, I've tried to put the more commonly used time zone
1771 at a higher priority. Since I'm not always able to decide which is the
1772 most commonly used, I'm willing to entertain arguments for altering the order.
1773
1774 ";
1775
1776 _print_pod_row($pod,1, 5,'ALIAS',15, 2,'TIME ZONE',20);
1777
1778 _warn_changes($abbrev_or,\%def_abbrev,3,14,44);
1779
1780 my (@abb) = sort keys %$abbrev_or;
1781 foreach my $abb (@abb) {
1782 my @tmp = @{ $$abbrev_or{$abb} };
1783
1784 my $first = $abb;
1785 my $opts1 = 'hashkey';
1786
1787 while (@tmp) {
1788 my $zone = shift(@tmp);
1789 shift(@tmp);
1790 shift(@tmp);
1791
1792 _print_pod_row($pod,0, 5,$first,15, 2,$zone,0);
1793 my $opts2 = 'list,hashval';
1794 $opts2 .= ',firstlist' if ($first);
1795 $opts2 .= ',lastlist' if (! @tmp);
1796 _print_mod_row($out, 2,$first,12,$opts1, 2,$zone,0,$opts2);
1797
1798 $first = '';
1799 $opts1 = 'hashkey,noquote';
1800 }
1801 }
1802
1803 print $out "
1804 );
1805 ";
1806 }
1807
1808 sub _do_zones_offsets {
1809 my($out,$pod) = @_;
1810
1811 my $offmod = _yaml_read("tzdata/_offmod");
1812
1813 # Start the offset output (in this case, no POD output since it
1814 # doesn't seem usefule.
1815
1816 print $out "
1817 \%Offmod = (
1818 ";
1819
1820 foreach my $offset (sort keys %$offmod) {
1821 my $mod = $$offmod{$offset};
1822 _print_mod_row($out, 2,$offset,10,'hashkey', 2,$mod,0,'hashval');
1823 }
1824
1825 print $out "
1826 );
1827 ";
1828 }
1829
1830 ############################################################################
1831 # PRINT OUT POD AND MODULE LINES
1832
1833 sub _print_pod_row {
1834 my($out,$header,@cols) = @_;
1835 my $under = '';
1836
1837 while (@cols) {
1838 my $indent = shift(@cols);
1839 my $val = shift(@cols);
1840 my $wid = shift(@cols);
1841 $wid = length($val) if (! $wid);
1842
1843 print $out ' 'x$indent,$val,' 'x($wid-length($val));
1844 $under .= ' 'x$indent . '-'x$wid;
1845 }
1846 print $out "\n";
1847 print $out "$under\n" if ($header);
1848 }
1849
1850 sub _print_mod_row {
1851 my($out,@cols) = @_;
1852
1853 while (@cols) {
1854 my $indent = shift(@cols);
1855 my $val = shift(@cols);
1856 my $wid = shift(@cols);
1857 my $opts = shift(@cols);
1858
1859 $val = "'$val'" unless ($opts =~ /noquote/);
1860 $val = lc($val) unless ($opts =~ /nocase/);
1861
1862 if ($opts =~ /hashkey/) {
1863 # nothing
1864
1865 } elsif ($opts =~ /hashval/) {
1866
1867 if ($opts =~ /firstlist/ && $opts =~ /lastlist/) {
1868 $val = "=> [ $val ],";
1869
1870 } elsif ($opts =~ /firstlist/) {
1871 $val = "=> [ $val,";
1872
1873 } elsif ($opts =~ /lastlist/) {
1874 $val = " $val ],";
1875
1876 } elsif ($opts =~ /list/) {
1877 $val = " $val,";
1878
1879 } else {
1880 $val = "=> $val,";
1881 }
1882
1883 } else {
1884 $val .= ',';
1885 }
1886
1887 $wid = length($val) if (! $wid);
1888
1889 my $rep = $wid-length($val);
1890 $rep = 0 if ($rep < 0);
1891 print $out ' 'x$indent,$val,' 'x$rep;
1892 }
1893 print $out "\n";
1894 }
1895
1896 ############################################################################
1897 # DEALING WITH THE ORDER OF ELEMENTS
1898
1899 # This takes a hash:
1900 # $in = { ELE => SUBELE => [YEAR1,YEAR2] }
1901 # and returns a hash of the form:
1902 # $out = { ELE => [ SUBELE, YEAR1, YEAR2,
1903 # SUBELE, YEAR1, YEAR2, ... ] }
1904 #
1905 # The order of the elements sorted based on the range.
1906 #
1907 sub _order_elements {
1908 my($in) = @_;
1909 my $out;
1910
1911 foreach my $ele (keys %$in) {
1912 my @in = _sort_by_years($$in{$ele});
1913
1914 $$out{$ele} = [];
1915 foreach my $subele (@in) {
1916 my($year1,$year2) = @{ $$in{$ele}{$subele} };
1917 push(@{ $$out{$ele} },($subele,$year1,$year2));
1918 }
1919 }
1920
1921 return $out;
1922 }
1923
1924 # This sorts the keys of a hash of the form:
1925 # $hash = { ELE => [YEAR1,YEAR2] }
1926 # by years.
1927 #
1928 # o An element that is active now always comes before one that isn't
1929 # active now.
1930 # i.e. [2000-2020] < [1900-2000] (now = 2010)
1931 #
1932 # o A modern European timezone (WET, CET, EET) comes before others.
1933 #
1934 # o An Antarctica element comes after one that is not Antarctica
1935 #
1936 # o A military timezone (A-Z) comes after one that is not
1937 #
1938 # o A UT/UTC/*GMT* timezone comes after one that is not
1939 #
1940 # o An element that is active later comes before one that is active
1941 # earlier.
1942 # i.e. [X-1970] < [X-1960]; [X-2040] < [X-2020]
1943 #
1944 # o An element that is active further in the past comes before one
1945 # that is active later.
1946 # i.e. [1930-X] < [1940-X]
1947 #
1948 # o Alphabetize the rest.
1949 #
1950 sub _sort_by_years {
1951 my($hash) = @_;
1952
1953 return sort { __sort_by_years($$hash{$a},$$hash{$b},$a,$b) } keys %$hash;
1954 }
1955 sub __sort_by_years {
1956 my($a,$b,$namea,$nameb) = @_;
1957
1958 # Find out which elements are currently active
1959 my $curra = ($$a[0] <= $curry && $$a[1] >= $curry ? 1 : 0);
1960 my $currb = ($$b[0] <= $curry && $$b[1] >= $curry ? 1 : 0);
1961
1962 # An element that is active now always comes before one that isn't
1963 # active now.
1964 if ($curra != $currb) {
1965 return -1 if ($curra);
1966 return 1;
1967 }
1968
1969 # A modern European timezone (WET, CET, EET) comes before others.
1970 if ($namea =~ /^(WET|CET|EET)$/) {
1971 return -1;
1972 } elsif ($nameb =~ /^(WET|CET|EET)$/) {
1973 return 1;
1974 }
1975
1976 # An Antarctica element comes after one that is not Antarctica
1977 if ($namea =~ /Antarctica/) {
1978 if ($nameb =~ /Antarctica/) {
1979 return $namea cmp $nameb;
1980 } else {
1981 return 1;
1982 }
1983 } elsif ($nameb =~ /Antarctica/) {
1984 return -1;
1985 }
1986
1987 # A military timezone (A-Z) comes after one that is not
1988
1989 if ($namea =~ /^[A-Z]$/) {
1990 if ($nameb =~ /^[A-Z]$/) {
1991 return $namea cmp $nameb;
1992 } else {
1993 return 1;
1994 }
1995 } elsif ($nameb =~ /^[A-Z]$/) {
1996 return -1;
1997 }
1998
1999 # A UT/UTC/*GMT* timezone comes after one that is not
2000
2001 if ($namea =~ /UT/ || $namea =~ /GMT/) {
2002 if ($nameb =~ /UT/ || $nameb =~ /GMT/) {
2003 return $namea cmp $nameb;
2004 } else {
2005 return 1;
2006 }
2007 } elsif ($nameb =~ /UT/ || $nameb =~ /GMT/) {
2008 return -1;
2009 }
2010
2011 # An element that is active later comes before one that is active
2012 # earlier.
2013 if ($$a[1] != $$b[1]) {
2014 return -1 if ($$a[1] > $$b[1]);
2015 return 1;
2016 }
2017
2018 # An element that is active further in the past comes before one
2019 # that is active later.
2020 if ($$a[0] != $$b[0]) {
2021 return -1 if ($$a[0] < $$b[0]);
2022 return 1;
2023 }
2024
2025 # We'll order anything else as America < Europe < Asia < other
2026 my ($posa,$posb);
2027 if ($namea =~ /^America/) { $posa = 1; }
2028 elsif ($namea =~ /^Europe/) { $posa = 2; }
2029 elsif ($namea =~ /^Asia/) { $posa = 3; }
2030 else { $posa = 4; }
2031 if ($nameb =~ /^America/) { $posb = 1; }
2032 elsif ($nameb =~ /^Europe/) { $posb = 2; }
2033 elsif ($nameb =~ /^Asia/) { $posb = 3; }
2034 else { $posb = 4; }
2035 return ($posa <=> $posb) if ($posa != $posb);
2036
2037 # Alphabetize the rest
2038 return $namea cmp $nameb;
2039 }
2040
2041 # This will warn if %curr is different than %prev.
2042 #
2043 sub _warn_changes {
2044 my($curr,$prev,$indent,$col1_len,$col2_len,$header) = @_;
2045
2046 my %tmp = map { $_,1 } (keys %$curr, keys %$prev);
2047
2048 foreach my $ele (sort keys %tmp) {
2049
2050 if (! exists $$curr{$ele}) {
2051
2052 # If the element doesn't exist in the current set of
2053 # elements, remove it from the previous set.
2054
2055 _warn_changes_ele($header,$ele,
2056 undef,$$prev{$ele},$indent,$col1_len,$col2_len);
2057
2058 } elsif (! exists $$prev{$ele}) {
2059
2060 # If the element doesn't exist in the old set, add it.
2061
2062 _warn_changes_ele($header,$ele,
2063 $$curr{$ele},undef,$indent,$col1_len,$col2_len);
2064
2065 } elsif (! ref($$prev{$ele})) {
2066
2067 # The previous element is defined as either a scalar:
2068 # PREV_FIRST
2069 # The current first element must be the same.
2070
2071 if ($$curr{$ele}[0] ne $$prev{$ele}) {
2072 _warn_changes_ele($header,$ele,
2073 $$curr{$ele},$$prev{$ele},
2074 $indent,$col1_len,$col2_len);
2075 }
2076
2077 } else {
2078
2079 # The previous element may be defined as a listref:
2080 # [ OVERRIDE, PREV_FIRST ]
2081 #
2082 # This will warn if the current first element is not the
2083 # same as PREV_FIRST.
2084 #
2085 # In the second case, it will also complain if OVERRIDE is not
2086 # in the list. Finally, it will reorder the list to move OVERRIDE
2087 # to the start of the list.
2088
2089 if ($$prev{$ele}[1] ne $$curr{$ele}[0]) {
2090 _warn_changes_ele($header,$ele,
2091 $$curr{$ele},$$prev{$ele},
2092 $indent,$col1_len,$col2_len);
2093
2094 } else {
2095 my @old = @{ $$curr{$ele} };
2096 my @new;
2097 my $found = 0;
2098 while (@old) {
2099 my $tz = shift(@old);
2100 my $y1 = shift(@old);
2101 my $y2 = shift(@old);
2102 if ($tz eq $$prev{$ele}[0]) {
2103 @new = ($tz,$y1,$y2,@new,@old);
2104 $found = 1;
2105 last;
2106 } else {
2107 push(@new,$tz,$y1,$y2);
2108 }
2109 }
2110 if ($found) {
2111 $$curr{$ele} = [@new];
2112 } else {
2113 _warn_changes_ele($header,$ele,
2114 $$curr{$ele},$$prev{$ele}[1],
2115 $indent,$col1_len,$col2_len);
2116 }
2117 }
2118 }
2119 }
2120 }
2121
2122 sub _warn_changes_ele {
2123 my($header,$ele,$curr,$prev,$indent,$col1_len,$col2_len) = @_;
2124
2125 my $val;
2126 if (! defined($curr)) {
2127 warn "*** REMOVE ***\n";
2128 if (ref($prev)) {
2129 $val = "[ $$prev[0], $$prev[1] ]";
2130 } else {
2131 $val = $prev;
2132 }
2133 } elsif (! defined($prev)) {
2134 warn "*** NEW ELEMENT ***\n";
2135 $val = $$curr[0];
2136 } else {
2137 warn "*** CHANGE ELEMENT ***\n";
2138 if (ref($prev)) {
2139 $val = "[ $$prev[0] => $$curr[0] ]";
2140 } else {
2141 $val = $$curr[0];
2142 }
2143 }
2144 warn "$header\n" if (defined $header);
2145
2146 $ele = "'$ele'";
2147 warn " "x$indent, $ele," "x($col1_len-length($ele)),"=> '$val'\n";
2148
2149 if (defined($curr)) {
2150 my @tmp = @$curr;
2151 while (@tmp) {
2152 my $subele = shift(@tmp);
2153 my $year1 = shift(@tmp);
2154 my $year2 = shift(@tmp);
2155 my($col2) = "'$subele'";
2156 my($col3) = ",$year1,$year2,";
2157
2158 warn "#"," "x($indent + $col1_len + 3), $col2,
2159 " "x($col2_len-length($col2)),"$col3\n";
2160 }
2161 }
2162 }
2163
2164 ############################################################################
2165 # DO_CLEAN
2166 ############################################################################
2167
2168 sub do_clean {
2169 print "Cleaning...\n";
2170 system("rm -rf tzdata* tzcode*");
2171 }
2172
2173 ############################################################################
2174
2175 sub _yaml_read {
2176 my($file) = @_;
2177 return {} if (! -e $file);
2178 my($data) = YAML::XS::LoadFile($file);
2179 return {} if (! defined $data);
2180 return $data;
2181 }
2182
2183 sub _yaml_write {
2184 my($data,$file,$backup) = @_;
2185
2186 rename($file,"$file.bak") if ($backup && -e $file);
2187 YAML::XS::DumpFile($file,$data);
2188 }
2189
2190 # Local Variables:
2191 # mode: cperl
2192 # indent-tabs-mode: nil
2193 # cperl-indent-level: 3
2194 # cperl-continued-statement-offset: 2
2195 # cperl-continued-brace-offset: 0
2196 # cperl-brace-offset: 0
2197 # cperl-brace-imaginary-offset: 0
2198 # cperl-label-offset: 0
2199 # End: