|
|
Create aliases for quick timezone checks
Using the hint above , I wrote up a perl script that does
something similar. It will work only on cities in /usr/share/zoneinfo.
#!/usr/bin/env perl
Save it in a file (e.g. itime). On terminal window: $ chmod +x itime $ ./itime Calcutta $./itime Eastern
Create aliases for quick timezone checks
I'm not sure what happened when you posted your code but 3 backslashes were stripped. One is fairly important as the script won't run without it. It's pretty handy though, thanks.
Create aliases for quick timezone checks
Thanks for the original posting and Perl solution. I made the perl script a little more Perlish. The first reason I changed was when I did "itime hongkong", I got something like "zoneinfo/hongkong blah ...", which wasn't quite pretty. It happens when timezone data files are right under /usr/share/zonefile, such as Turkey, Poland, etc. This new version prints only city name and its local time. The second change was now it can accept case-insensitive city name. In other words, you get the same result whether you type "seoul" or "Seoul".
#!/usr/bin/perl -w
use strict;
use File::Find;
use File::Basename;
my $zoneDir="/usr/share/zoneinfo";
my $city = shift || die "Usage: itime city\n";
find(\&wanted, $zoneDir);
sub wanted {
if ( -f $_ && $_ =~ /$city/i ) {
$ENV{'TZ'}=basename($File::Find::dir)."/$_";
my $time=localtime();
print "$_ $time\n";
}
}
Create aliases for quick timezone checks
dang... geeklog ate up backslashes when I posted as HTML, though it was okay when I previewed it. |
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysNo new commentsLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.05 seconds |
|