[tz] samezone.pl

Arthur David Olson arthurdavidolson at gmail.com
Tue Feb 26 15:45:03 UTC 2013


I've attached a potentially useful script; it also appears in tab-mangled
form below; it's designed to identify time zones that are the same in the
long run.

Given the name of a zone.tab file and the name of a time-zone-binary
directory, the script runs through the zones mentioned in zone.tab and
finds the associated POSIX string that applies after the last transition
time specified in the zone's binary file. Each line of output begins with a
POSIX string, followed by the name of each zone to which that string
applies; output is sorted by POSIX string. So:

    AFT-4:30    Asia/Kabul
    AKST9AKDT,M3.2.0,M11.1.0    America/Anchorage America/Juneau
America/Sitka America/Yakutat America/Nome
    ...

There's surely room for improvement.

        @dashdashado

#!/bin/perl

my $O = $0;

$O =~ s at .*[\/\\]@@;
$O =~ s at .pl$@@i;

if ($#ARGV != 1) {
    printf STDERR "$O: usage is $O zone.tab tz-binary-directory\n";
    exit(1);
}

my ($zonetab, $tzdir) = @ARGV;

open(S, "<$zonetab") || die("cannot open $zonetab");
while(<S>) {
    s@[\r\n]@@g;
    s@\s*#.*@@;
    $zone = (split())[2];
    $zone eq "" && next;
    $binary = "$tzdir/$zone";
    open(T, "<$binary") || die("cannot open $binary");
    $posix = ();
    while (<T>) {
        $posix = $_;
    }
    close(T);
    $posix =~ s@[\r\n]@@g;
    if ($posix eq "") {
        $posix = $zone;
    }
    $result = $results{$posix};
    if ($result ne "") {
        $result .= " ";
    }
    $result .= $zone;
    $results{$posix} = $result;
}
close(S);

foreach (sort keys %results) {
    print "$_\t$results{$_}\n";
}


exit(0);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm.icann.org/pipermail/tz/attachments/20130226/b6b86593/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: samezone.pl
Type: application/octet-stream
Size: 741 bytes
Desc: not available
Url : http://mm.icann.org/pipermail/tz/attachments/20130226/b6b86593/samezone.pl 


More information about the tz mailing list