1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
|
#
# Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
#
#
#
# Perl script to generate ZoneData from Olson public time zone data.
#
# For J2SE before JDK1.3, see ../../README how to update TimeZone.java
# static TimeZoneData.
# For J2SE since JDK1.4, this script is used to generate testdata(reference)
# for ZoneData.sh which is one of TimeZone Regression test.
$continue = 0;
# verbose flag
$verbose = 0;
# version of Olson's public zone information (e.g. "tzdata2000g")
$versionName = "unknown";
# Number of testdata files.
$count = 5;
# Display name datafile
$displayNameFile = "displaynames.txt";
# time zone IDs to be generated. If it's empty, then generate all time
# zone in the tzdata files.
@javatzids = ();
#
# Parses command-line options
#
while ($#ARGV >= 0) {
if ($ARGV[0] =~ /^-v/) {
$verbose = 1;
} elsif ($ARGV[0] =~ /^-V/) {
$versionName = $ARGV[1];
shift(@ARGV);
} else {
@javatzids = &readIDs($ARGV[0]);
last;
}
shift(@ARGV);
}
# Beginning year of testdata
($sec, $min, $hour, $mday, $mon, $year, $wday, $ydat, $isdst) = gmtime();
$baseYear = $year+1900;
if ($verbose == 1) {
print STDERR "baseYear : $baseYear\n";
print STDERR "versionName : $versionName\n";
}
# Open display name datafile
open (DNFD, ">$displayNameFile") || die ("$displayNameFile : open error.\n");
while(<STDIN>) {
chop;
if (/^\#/) { # skip comment line
next;
}
@item = ("foo");
# Zone NAME GMTOFF RULES FORMAT [UNTIL]
if ($continue == 1) {
s/\#.*//; # chop trailing comments
s/\s+$//;
s/^\s+//;
@item = split(/\s+/, $_);
@item = ($zname, @item); # push zone name
} elsif (/^Zone/) {
s/\#.*//; # chop trailing comments
s/\s+$//;
@item = split(/\s+/, $_);
$zname = $item[1];
if (defined ($zones{$name})) {
printf STDERR "WARNING: duplicate definition of zone $name\n";
}
shift(@item);
}
if (@item[0] ne "foo") {
if($#item == 3) { # find out no UNTIL line
$item[3] =~ s/%/%%/;
$zones{$item[0]} = "Zone $item[0]\t$item[1]\t$item[2]\t$item[3]";
} else {
$continue = 1;
next;
}
}
# Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S
if (/^Rule/) {
($rule, $name, $from, $to, $type, $in, $on, $at, $save, $letter)
= split(/\s+/, $_);
# matches specified year?
for ($i = 0; $i < $count; $i++) {
if ($from <= $baseYear+$i && ($to >= $baseYear+$i || $to eq "max")
|| ($from == $baseYear+$i && $to eq "only")) {
if ($save ne "0") {
$rules[$i]{$name . "0"} = $_;
} else {
$rules[$i]{$name . "1"} = $_;
}
} else {
if ($from <= $baseYear) {
if ($save ne "0") {
$oldRules[0]{$name} = $_;
} else {
$oldRules[1]{$name} = $_;
}
}
}
}
}
$continue = 0;
}
#
# Prepare output files
#
for ($i = 0, $fd = 0; $i < $count; $i++, $fd++) {
$filename = "year".($baseYear+$i);
open ($fd, ">$filename") || die ("$filename : open error.\n");
print $fd "# Based on $versionName\n";
}
#
# If no IDs are specified, produce test data for all zones.
#
if ($#javatzids < 0) {
@javatzids = keys(%zones);
}
foreach $z (@javatzids) {
#
# skip any Riyadh zones; ZoneData.java can't handle Riyada zones
#
next if ($z =~ /Riyadh/);
for ($i = 0, $fd = 0; $i < $count; $i++, $fd++) {
if (!defined($zones{$z})) {
printf $fd "$z ?\n";
printf STDERR "WARNING: java zone $z not found\n";
next;
}
@item = split(/\s+/, $zones{$z});
if ($item[3] ne "-") {
printf $fd "$item[1] $item[2] ";
if (defined($rules[$i]{$item[3] . "0"})
&& defined($rules[$i]{$item[3] . "1"})) {
$rule0 = $rules[$i]{$item[3] . "0"};
$rule1 = $rules[$i]{$item[3] . "1"};
@r0 = split(/\s+/, $rule0);
@r1 = split(/\s+/, $rule1);
printf $fd "$r0[5] $r0[6] $r0[7] $r1[5] $r1[6] $r1[7] $r0[8]\n";
printf $fd "$zones{$z}\n";
printf $fd "$rule0\n";
printf $fd "$rule1\n";
if ($i == 0) {
$std = $dst = $item[4];
$std =~ s/%%s/$r1[9]/;
if ($r1[9] eq "-") {
$std =~ s/-//;
}
$dst =~ s/%%s/$r0[9]/;
if ($r0[9] eq "-") {
$dst =~ s/-//;
}
if ("$std$dst" =~ /[A-Z]/) {
print DNFD "$item[1] $std $dst\n";
}
}
} else {
printf $fd "-\n"; # In case we cannot find Rule, assume no DST.
printf $fd "$zones{$z}\n";
printf STDERR "WARNING: $z no rules defined for $item[3]\n";
if ($i == 0) {
# About 30 time zones (e.g. Asia/Tokyo needs the following
# recovery.
if ($item[4] =~ m/%/) {
@r0 = split(/\s+/, $oldRules[0]{$item[3]});
@r1 = split(/\s+/, $oldRules[1]{$item[3]});
if ($i == 0) {
$std = $dst = $item[4];
$std =~ s/%%s/$r1[9]/;
if ($r1[9] eq "-") {
$std =~ s/-//;
}
$dst =~ s/%%s/$r0[9]/;
if ($r0[9] eq "-") {
$dst =~ s/-//;
}
if ("$std$dst" =~ /[A-Z]/) {
print DNFD "$item[1] $std $dst\n";
}
}
} else {
if ("$item[4]" =~ /[A-Z]/) {
print DNFD "$item[1] $item[4]\n";
}
}
}
}
} else {
printf $fd "$item[1] $item[2] $item[3]\n";
printf $fd "$zones{$z}\n";
if ($i == 0 && "$item[4]" =~ /[A-Z]/) {
print DNFD "$item[1] $item[4]\n";
}
}
}
}
#
# Close all the output files
#
close (DNFD);
for ($i = 0, $fd = 0; $i < $count; $i++, $fd++) {
close ($fd);
}
#
# Sort the displaynames.txt file
#
open my $fh, '<', $displayNameFile || die ("Can't open $displayNameFile for sorting\n");;
chomp(my @names = <$fh>);
close $fh;
open my $fh, '>', $displayNameFile;
foreach $line (sort @names) { print $fh $line,"\n"; }
close $fh;
exit(0);
sub readIDs {
local ($file) = @_;
local (@ids, $i);
open(F, $file) || die "Fatal: can't open $file.\n";
$i = 0;
while (<F>) {
chop;
if (/^\#/) { # skip comment line
next;
}
# trim any leading and trailing space
s/^\s+//;
s/\s+$//;
if (/^\s*$/) { # skip blank line
next;
}
$ids[$i++] = $_;
}
close(F);
return @ids;
}
|