/
bc-zdump2abbrev.pl
executable file
·38 lines (24 loc) · 1.03 KB
/
bc-zdump2abbrev.pl
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
#!/bin/perl
# For each time zone in the output of:
# find /usr/share/zoneinfo -type f | xargs -n 1 zdump -v
# find the latest (and thus most likely current) abbreviation
# Note that abbreviations are not unique (tzdata uses EDT for both the
# United States and Australia's eastern daylight timezones), but this
# should help me canonize time zone names (maybe)
require "/usr/local/lib/bclib.pl";
my(%latest,%abbrev,%geonames);
# limit to those timezones actually found in geonames
my(%geonames) = list2hash(split(/\n/,read_file("$bclib{githome}/ASTRO/tz-names-in-geonames.txt")));
open(A,"bzcat $bclib{githome}/ASTRO/zdump.txt.srt.bz2|");
while (<A>) {
# we need: filename, UTC year, abbrev
my(@data) = split(/\s+/,$_);
my($fname, $utcy, $abbrev) = @data[0,5,13];
$fname=~s%/usr/share/zoneinfo/%%;
unless ($geonames{$fname}) {next;}
# if I already have later abbrev for this tz, ignore
if ($latest{$fname} > $utcy) {next;}
$latest{$fname} = $utcy;
$abbrev{$fname} = $abbrev;
}
for $i (keys %abbrev) {print "$i $abbrev{$i}\n";}