File indexing completed on 2024-12-08 09:27:33

0001 $filename = $ARGV[0]; # "somecities.dat"
0002 
0003 &initTZList();
0004 
0005 open ( CITIES, $filename ) || die "file $filename not found";
0006 while ( $city = <CITIES> ) {
0007     chop $city;
0008     $_ = $city;
0009     $fieldcount = s/://g;
0010     @fields = split(/:/, $city );
0011 
0012   for ( $i=0; $i<$fieldcount; $i++) {
0013     $fields[$i] =~ s/^\s+//;
0014       $fields[$i] =~ s/\s+$//;
0015     }
0016     #printf("calling 0: %s, 1: %s, 2: %s \n", $fields[0], $fields[1], $fields[2]);
0017 
0018   #Only calculate TZ if it is currently set to "x"
0019   if ($fields[11]=="x") {
0020         $TZ = &calcTZ($fields[2], $fields[1]);
0021   } else {
0022         $TZ = $fields[11];
0023     }
0024 
0025     if ( $fieldcount == 11 ) {
0026         printf ( "%-32s :", $fields[0] ); # City
0027     printf ( " %-21s :", $fields[1] ); # Province
0028     printf ( " %-21s :", $fields[2] ); # Country
0029     printf ( " %2s :", $fields[3] ); # Lat deg
0030     printf ( " %2s :", $fields[4] ); # Lat min
0031     printf ( " %2s :", $fields[5] ); # lat sec
0032     printf ( " %1s :", $fields[6] ); # lat sign
0033     printf ( " %3s :", $fields[7] ); # lon deg
0034     printf ( " %2s :", $fields[8] ); # long min
0035     printf ( " %2s :", $fields[9] ); # lon sec
0036     printf ( " %1s :", $fields[10] ); # lon sign
0037         printf ( " %s", $TZ );
0038     }
0039     else {
0040         # old data: no privince field, replace with blank
0041         printf ( "%-32s :", $fields[0] ); # City
0042     printf ( " %-21s :", "" ); # Province
0043     printf ( " %-21s :", $fields[1] ); # Country
0044     printf ( " %2s :", $fields[2] ); # Lat deg
0045     printf ( " %2s :", $fields[3] ); # Lat min
0046     printf ( " %2s :", $fields[4] ); # lat sec
0047     printf ( " %1s :", $fields[5] ); # lat sign
0048     printf ( " %3s :", $fields[6] ); # lon deg
0049     printf ( " %2s :", $fields[7] ); # long min
0050     printf ( " %2s :", $fields[8] ); # lon sec
0051     printf ( " %1s :", $fields[9] ); # lon sign
0052         printf ( " %s", $TZ );
0053     }
0054   printf"\n";
0055 }
0056 
0057 sub calcTZ {
0058     local($country);
0059     local($province);
0060     local($TZ);
0061     $country=$_[0];
0062     $province=$_[1];
0063     # printf ("calculating TZ for country=x%sx, province=x%sx\n", $country, $province);
0064 
0065     $TZ = $timezone{$country};
0066     # printf ("Current result: %s\n", $TZ);
0067     if ( ($TZ eq "" ) or ($TZ eq "x")) {
0068         if ( $country eq "USA" ) { 
0069             $TZ = $us_timezone{$province}; 
0070         }
0071         if ( $country eq "Canada" ) { 
0072             $TZ = $ca_timezone{$province}; 
0073         }
0074         if ( $country eq "Australia" ) { 
0075             $TZ = $au_timezone{$province}; 
0076         }
0077         if ( $TZ eq "" ) {
0078             $TZ = "x";
0079       }
0080     }
0081     $TZ;
0082 }
0083 
0084 sub initTZList{
0085     $timezone{"Afghanistan"} = "4.5";
0086     $timezone{"Algeria"} = "1.0";
0087     $timezone{"Antarcti"} = "x"; # covers several TZs
0088     $timezone{"Antigua"} = "x";
0089     $timezone{"Argentina"} = "-3.0";    
0090     $timezone{"Ascension Island"} = "0.0";
0091     $timezone{"Australia"} = "x";   # covers several TZs
0092     $timezone{"Austria"} = "1.0";
0093     $timezone{"Azores"} = "-1.0";
0094     $timezone{"Bahamas"} = "-5.0";
0095     $timezone{"Bahrain"} = "x";  # illegible in map
0096     $timezone{"Bangladesh"} = "6.0";
0097     $timezone{"Barbados"} = "x";
0098     $timezone{"Belgium"} = "1.0";
0099     $timezone{"Belize"} = "-6.0";
0100     $timezone{"Bermuda"} = "x";
0101     $timezone{"Bolivia"} = "-4.0";
0102     $timezone{"Bosnia"} = "1.0";
0103     $timezone{"Brazil"} = "x";  # covers several TZs
0104     $timezone{"Brunei"} = "8.0";
0105     $timezone{"Bulgaria"} = "2.0";
0106     $timezone{"Cabo Verde"} = "1.0";
0107     $timezone{"Caicos Islands"} = "x";
0108     $timezone{"Cameroon"} = "1.0";
0109     $timezone{"Canada"} = "x"; # covers several TZs
0110     $timezone{"Canary Island"} = "0.0";
0111     $timezone{"Cayman Islands"} = "x";
0112     $timezone{"Chad"} = "1.0";
0113     $timezone{"Chile"} = "-4.0";
0114     $timezone{"China"} = "8.0";
0115     $timezone{"Colombia"} = "-5.0";
0116     $timezone{"Costa Rica"} = "-6.0";
0117     $timezone{"Croatia"} = "1.0";
0118     $timezone{"Cuba"} = "-5.0";
0119     $timezone{"Cyprus"} = "2.0";
0120     $timezone{"Czech Republic"} = "1.0";
0121     $timezone{"Denmark"} = "1.0";
0122     $timezone{"Djibouti"} = "3.0";
0123     $timezone{"Dominican Repub"} = "-4.0";
0124     $timezone{"Ecuador"} = "-5.0";
0125     $timezone{"Egypt"} = "2.0";
0126     $timezone{"El Salvador"} = "-6.0";
0127     $timezone{"Ethiopia"} = "3.0";
0128     $timezone{"Falkland Island"} = "-4.0";
0129     $timezone{"Fiji"} = "12.0";
0130     $timezone{"Finland"} = "2.0";
0131     $timezone{"France"} = "1.0";
0132     $timezone{"French Guiana"} = "-3.0";
0133     $timezone{"French Polynesia"} = "-10.0";  # mostly
0134     $timezone{"Gabon"} = "1.0";
0135     $timezone{"Gambia"} = "0.0";
0136     $timezone{"Germany"} = "1.0";
0137     $timezone{"Ghana"} = "0.0";
0138     $timezone{"Greece"} = "2.0";
0139     $timezone{"Greenland"} = "-3.0";
0140     $timezone{"Guadalcanal"} = "x";
0141     $timezone{"Guam"} = "x";
0142     $timezone{"Guatemala"} = "-6.0";
0143     $timezone{"Guyana"} = "-4.0";
0144     $timezone{"Haiti"} = "-5.0";
0145     $timezone{"Honduras"} = "-6.0";
0146     $timezone{"Hong Kong"} = "8.0";
0147     $timezone{"Hungary"} = "1.0";
0148     $timezone{"Iceland"} = "0.0";
0149     $timezone{"India"} = "5.5";
0150     $timezone{"Indonesia"} = "x"; # covers several TZs
0151     $timezone{"Iran"} = "3.5";
0152     $timezone{"Iraq"} = "3.0";
0153     $timezone{"Ireland"} = "0.0";
0154     $timezone{"Isle of Man"} = "0.0";
0155     $timezone{"Israel"} = "2.0";
0156     $timezone{"Italy"} = "1.0";
0157     $timezone{"Jamaica"} = "-5.0";
0158     $timezone{"Japan"} = "9.0";
0159     $timezone{"Jordan"} = "2.0";
0160     $timezone{"Kenya"} = "3.0";
0161     $timezone{"Kuwait"} = "3.0";
0162     $timezone{"Lebanon"} = "2.0";
0163     $timezone{"Liberia"} = "0.0";
0164     $timezone{"Libya"} = "1.0";
0165     $timezone{"Luxembourg"} = "1.0";
0166     $timezone{"Madeira Island"} = "0.0";
0167     $timezone{"Malaysia"} = "8.0";
0168     $timezone{"Maldive Island"} = "5.0";
0169     $timezone{"Malta"} = "1.0";
0170     $timezone{"Marshall Islands"} = "12.0";
0171     $timezone{"Mauritius"} = "4.0";
0172     $timezone{"Mexico"} = "x"; # covers several TZs
0173     $timezone{"Micronesia"} = "x";
0174     $timezone{"Monaco"} = "1.0";
0175     $timezone{"Morocco"} = "0.0";
0176     $timezone{"Myanmar"} = "9.5";
0177     $timezone{"Nepal"} = "5.75";
0178     $timezone{"Netherlands"} = "1.0";
0179     $timezone{"New Caledonia"} = "x";
0180     $timezone{"New Zealand"} = "12.0"; # apart from Chatham Islands
0181     $timezone{"Nicaragua"} = "6.0";
0182     $timezone{"Nigeria"} = "1.0";
0183     $timezone{"Northern Ireland"} = "0.0";
0184     $timezone{"Norway"} = "1.0";
0185     $timezone{"Pakistan"} = "5.0";
0186     $timezone{"Palau"} = "x";
0187     $timezone{"Panama"} = "-5.0";
0188     $timezone{"Papua"} = "10.0";
0189     $timezone{"Paraguay"} = "-4.0";
0190     $timezone{"Peru"} = "-5.0";
0191     $timezone{"Philippines"} = "8.0";
0192     $timezone{"Poland"} = "1.0";
0193     $timezone{"Portugal"} = "0.0"; 
0194     $timezone{"Qatar"} = "x"; # illegible on map
0195     $timezone{"Romania"} = "2.0";
0196     $timezone{"Russia"} = "x"; # covers several TZs
0197     $timezone{"Samoa"} = "x";
0198     $timezone{"Saudi Arabia"} = "3.0";
0199     $timezone{"Scotland"} = "0.0";
0200     $timezone{"Senegal"} = "0.0";
0201     $timezone{"Serbia"} = "1.0";
0202     $timezone{"Seychelles"} = "4.0";
0203     $timezone{"Singapore"} = "8.0";
0204     $timezone{"Slowenien"} = "1.0";
0205     $timezone{"South Africa"} = "2.0";
0206     $timezone{"South Korea"} = "9.0";
0207     $timezone{"Spain"} = "1.0";
0208     $timezone{"Sri Lanka"} = "5.5";
0209     $timezone{"St. Lucia"} = "x";
0210     $timezone{"Sudan"} = "2.0";
0211     $timezone{"Sweden"} = "1.0";
0212     $timezone{"Switzerland"} = "1.0";
0213     $timezone{"Syria"} = "2.0";
0214     $timezone{"Tahiti"} = "x";
0215     $timezone{"Taiwan"} = "8.0";
0216     $timezone{"Tanzania"} = "3.0";
0217     $timezone{"Thailand"} = "7.0";
0218     $timezone{"Tibet"} = "8.0";
0219     $timezone{"Trinidad"} = "-4.0";
0220     $timezone{"Tunisia"} = "1.0";
0221     $timezone{"Turkey"} = "2.0";
0222     $timezone{"UK Territory"} = "x";
0223     $timezone{"US Teritory"} = "x";
0224     $timezone{"US Territory"} = "x";
0225     $timezone{"USA"} = "x";         # covers several TZs
0226     $timezone{"Uganda"} = "3.0";
0227     $timezone{"Ukraine"} = "2.0";
0228     $timezone{"United Arab Emirates"} = "4.0";
0229     $timezone{"United Kingdom"} = "0.0";
0230     $timezone{"Uruguay"} = "-3.0";
0231     $timezone{"Vanuatu"} = "11.0";
0232     $timezone{"Venezuela"} = "-4.0";
0233     $timezone{"Virgin Islands"} = "x";
0234     $timezone{"Yemen"} = "3.0";
0235     $timezone{"Zaire"} = "x";   # covers several TZs
0236     $timezone{"Zambia"} = "2.0";
0237 
0238 #Province-specific TZ's
0239 # US States
0240     $us_timezone{"Alabama"} = "-6.0";
0241   $us_timezone{"Alaska"} = "-9.0";
0242   $us_timezone{"Arizona"} = "-7.0"; #AZ does not use daylight savings time
0243   $us_timezone{"Arkansas"} = "-6.0";
0244   $us_timezone{"California"} = "-8.0";
0245   $us_timezone{"Colorado"} = "-7.0";
0246   $us_timezone{"Connecticut"} = "-5.0";
0247   $us_timezone{"Delaware"} = "-5.0";
0248   $us_timezone{"Florida"} = "-5.0"; #a small part of western FL is -6.0 (CST)
0249   $us_timezone{"Georgia"} = "-5.0";
0250   $us_timezone{"Hawaii"} = "-10.0";
0251   $us_timezone{"Idaho"} = "x"; #northern ID is -8.0; southern ID is -7.0
0252   $us_timezone{"Illinois"} = "-6.0";
0253   $us_timezone{"Indiana"} = "-5.0"; #two corners of IN are in -6.0; the rest of IN does not use savings time
0254   $us_timezone{"Iowa"} = "-6.0";
0255   $us_timezone{"Kansas"} = "-6.0"; #4 counties in Western KS are -7.0
0256   $us_timezone{"Kentucky"} = "x"; #half is -5.0, half is -6.0
0257   $us_timezone{"Louisiana"} = "-6.0";
0258   $us_timezone{"Maine"} = "-5.0";
0259   $us_timezone{"Maryland"} = "-5.0";
0260   $us_timezone{"Massachusetts"} = "-5.0";
0261   $us_timezone{"Michigan"} = "-5.0";
0262   $us_timezone{"Minnesota"} = "-6.0";
0263   $us_timezone{"Mississippi"} = "-6.0";
0264   $us_timezone{"Missouri"} = "-6.0";
0265   $us_timezone{"Montana"} = "-7.0";
0266   $us_timezone{"Nebraska"} = "x"; #eastern 2/3 is -6.0, the rest is -7.0
0267   $us_timezone{"Nevada"} = "-8.0";
0268   $us_timezone{"New Hampshire"} = "-5.0";
0269   $us_timezone{"New Jersey"} = "-5.0";
0270   $us_timezone{"New Mexico"} = "-7.0";
0271   $us_timezone{"New York"} = "-5.0";
0272   $us_timezone{"North Carolina"} = "-5.0";
0273   $us_timezone{"North Dakota"} = "x"; #3/4 is -6.0, the rest is -7.0
0274   $us_timezone{"Ohio"} = "-5.0";
0275   $us_timezone{"Oklahoma"} = "-6.0";
0276   $us_timezone{"Oregon"} = "-8.0"; #one county in Easter OR is -7.0
0277   $us_timezone{"Pennsylvania"} = "-5.0";
0278   $us_timezone{"Rhode Island"} = "-5.0";
0279   $us_timezone{"South Carolina"} = "-5.0";
0280   $us_timezone{"South Dakota"} = "x"; #1/2 is -6.0, the rest is -7.0
0281   $us_timezone{"Tennessee"} = "x"; #2/3 is -6.0, the rest is -5.0
0282   $us_timezone{"Texas"} = "-6.0"; #two westernmost counties are -7.0
0283   $us_timezone{"Utah"} = "-7.0";
0284   $us_timezone{"Vermont"} = "-5.0";
0285   $us_timezone{"Virginia"} = "-5.0";
0286   $us_timezone{"Washington"} = "-8.0";
0287   $us_timezone{"West Virginia"} = "-5.0";
0288   $us_timezone{"Wisconsin"} = "-6.0";
0289   $us_timezone{"Wyoming"} = "-7.0";
0290   $us_timezone{"DC"} = "-5.0";
0291   $us_timezone{"Puerto Rico"} = "-5.0";
0292 
0293 #Canadian Provinces
0294     $ca_timezone{"Alberta"} = "-7.0";
0295   $ca_timezone{"British Columbia"} = "-8.0"; #Small parts of Eastern BC are -7.0
0296     $ca_timezone{"Labrador"} = "-4.0";
0297   $ca_timezone{"Manitoba"} = "-6.0"; 
0298     $ca_timezone{"New Brunswick"} = "-4.0";
0299     $ca_timezone{"Newfoundland"} = "-3.5"; 
0300     $ca_timezone{"Northwest Territories"} = "-7.0";
0301   $ca_timezone{"Nova Scotia"} = "-4.0";
0302     $ca_timezone{"Nunavut"} = "x"; #spans 3 timezones!  -5, -6 and -7
0303   $ca_timezone{"Ontario"} = "x"; #Eastern 2/3 is -5, the rest is -6
0304     $ca_timezone{"Prince Edward Island"} = "-4.0";
0305     $ca_timezone{"Quebec"} = "-5.0"; #small eastern section is -4
0306     $ca_timezone{"Saskatchewan"} = "-6.0"; #does not use savings time.
0307     $ca_timezone{"Yukon"} = "-8.0";
0308 
0309 #Australian Provinces
0310     $au_timezone{"ACT"} = "+10.0";
0311     $au_timezone{"New South Wales"} = "+10.0";
0312   $au_timezone{"Northern Territory"} = "+9.0";
0313     $au_timezone{"Queensland"} = "+10.0";
0314     $au_timezone{"South Australia"} = "+9.0";
0315     $au_timezone{"Tasmania"} = "+10.0";
0316     $au_timezone{"Victoria"} = "+10.0";
0317     $au_timezone{"Western Australia"} = "+8.0";
0318 }