Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Create aliases for quick timezone checks UNIX
To quickly check the time in other parts of the world, you may wanna add some lines to your ~/.login file.

#timezone
alias Seoul env TZ=Asia/Seoul date
alias Vienna env TZ=Europe/Vienna date
alias LA env TZ=US/Pacific date
Find all possible locations in /usr -> share -> zoneinfo. Open each folder within that directory to see the available cities, as shown in the Asia and Europe examples above.
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[3,852 views]  

Create aliases for quick timezone checks | 11 comments | Create New Account
Click here to return to the 'Create aliases for quick timezone checks' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create aliases for quick timezone checks
Authored by: ali baba on Aug 19, '03 11:08:54AM

com on you could have been a tad more elaborate here :-) it sound very useful.. i can't seem to find the invisible .login file in my home directory or elsewhere and once altered where do i quickly check the time-zone?



[ Reply to This | # ]
Create aliases for quick timezone checks
Authored by: ryangreenberg on Aug 19, '03 11:20:01AM

Well, if the .login file in your home directory isn't there, then you could create it.

To use the aliases, type the name of the city in the terminal. (e.g. using the original hint as an example, type "LA" and then return to see the current Pacific time).



[ Reply to This | # ]
sorry posted before in wrong branch of this thread
Authored by: ali baba on Aug 20, '03 04:21:20AM

hi thanks for responding.. i am not too familiar with these kind of manoeuvres.. is it ok if i fire up pico, copy your lines (i am in holland and accidentally my relatives are in LA and seoul) and save the file naming it ".login" in my home directory?



[ Reply to This | # ]
Create aliases for quick timezone checks
Authored by: bici on Aug 21, '03 12:07:26AM
to find .files "dotfiles" issue the command ls -a. In this case i don't add anything to .login file. Instead i add all my aliases to my own /Users/bici/Library/init/tcsh/aliases.mine file. This way any changes only apply to your login id. (this assumes that you use the tcsh shell. your mileage might vary)

---
sempre in giro

[ Reply to This | # ]

Or, if you're using bash...
Authored by: officemonkey on Aug 19, '03 08:21:02PM
If you're using bash (you know who you are), this will work for you.
#timezone
alias Seoul='env TZ=Asia/Seoul date'
alias Vienna='env TZ=Europe/Vienna date'
alias LA='env TZ=US/Pacific date'


[ Reply to This | # ]
Create aliases for quick timezone checks
Authored by: mojo6771 on Aug 19, '03 11:25:44PM
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

use File::Find;
use File::Basename;

my $zoneDir="/usr/share/zoneinfo";
if ( $#ARGV != 0 ) { print "Usage : $0 \n"; exit ; }
my $city = $ARGV[0];

sub findWanted {
local $time;
local $timezone;
if ( -f $_ && $_ eq $city ){
$timezone= basename($File::Find::dir)."/$city";
$ENV{'TZ'}=$timezone;
$time=localtime();
print "$timezone $time \n";
}
}

find(\&findWanted, $zoneDir) ;
exit;


Save it in a file (e.g. itime).
On terminal window:
$ chmod +x itime
$ ./itime Calcutta
$./itime Eastern




[ Reply to This | # ]
Create aliases for quick timezone checks
Authored by: kevco on Aug 20, '03 11:32:01PM

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.

Here is the code with missing backslashes:

#!/usr/bin/env perl

use File::Find;
use File::Basename;

my $zoneDir="/usr/share/zoneinfo";
if ( $#ARGV != 0 ) { print "Usage : $0 \n"; exit ; }
my $city = $ARGV[0];

sub findWanted {
local $time;
local $timezone;
if ( -f $_ && $_ eq $city ){
$timezone= basename($File::Find::dir)."/$city";
$ENV{'TZ'}=$timezone;
$time=localtime();
print "$timezone $time \n";
}
}

find(\&findWanted, $zoneDir) ;
exit;



[ Reply to This | # ]
Create aliases for quick timezone checks
Authored by: ilovja on Aug 28, '03 11:42:50PM
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";
    }
}


[ Reply to This | # ]
Create aliases for quick timezone checks
Authored by: ilovja on Aug 28, '03 11:46:24PM

dang... geeklog ate up backslashes when I posted as HTML, though it was okay when I previewed it.

#!/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";
}
}



[ Reply to This | # ]
Create aliases for quick timezone checks
Authored by: ali baba on Aug 20, '03 04:19:12AM

hi thanks for responding.. i am not too familiar with these kind of manoeuvres.. is it ok if i fire up pico, copy your lines (i am in holland and accidentally my relatives are in LA and seoul) and save the file naming it ".login" in my home directory?



[ Reply to This | # ]
Create aliases for quick timezone checks
Authored by: mojo6771 on Aug 20, '03 10:15:55AM

No..

Do not save the above script as .login.

The script is different way of achieving the goal given by the
originally hint.

You yank the lines above and using pico (or other editor)
save them as "itime".
You can save it on your Desktop (or any other directory).

Instructions if you save to Desktop.


1. Save as "~/Desktop/itime"
2. In terminal window "chmod +x itime".

Now to try it out in terminal window.

[prompt] ~/Desktop/itime Seoul




[ Reply to This | # ]