Apps :: Looking for World Time Application



Some more perl could convert to 24 hr format (might try it), but it might be lazier to  call the system's date command from within perl to convert times.

There's  zdump, if you know the desired timezone, eg EST:

Code Sample
$ zdump EST


but this seems to be giving wrong answers on dsl.   Locale issues?

With 24-hr output and taking multiple city arguments:

EDIT: added  -f option to access extended listing of city times, useage -h

EDIT2&3:  now outputs 5-char time in justified columns for tidy display.  Set width with option -w

EDIT4:  Web source is www.whatisthetime.com.  -f switch has no effect for this.

Code Sample
#!/usr/bin/perl

# Use -h for useage
# 24-hour, multi arg version
# -f option for long city listing
# -w option to set output width

use strict;
use warnings;
use Getopt::Std;

my $defaultwidth = 14; # default output width in chars, overidden by -w switch

#========================================

sub twelveto24{
# adapted from http://keithdevens.com/weblog/archive/2006/Feb/02/12-to-24
   my ($hr, $per) = @_;
   return '00' if($hr == 12 and $per eq 'AM');
   return $hr+12 if($hr != 12 and $per eq 'PM');
   if (length($hr) eq 1){ $hr = '0' . $hr };
   return $hr;
}

#=========================================

my ($city, $URL, $displaywidth);
our ($opt_f, $opt_h, $opt_w);
my $download = "/tmp/citytimes.$$.html";


# Parse  cli switches
getopts('fhw:');

if ($opt_h) { die "Useage: $0 [-f|-h] [-w WIDTH ] somecity1 somecity2 somecity3 ..\n" };
if (!$ARGV[0]) {die "No city specified"};
if ($opt_w){
if ($opt_w !~ /\d+/ ) { die "Invalid argument to -w option"
} else { $displaywidth = $opt_w }
} else { $displaywidth = $defaultwidth }

#~ if ($opt_f) { $URL = "http://www.timeanddate.com/worldclock/full.html"
#~ } else { $URL = "http://www.timeanddate.com/worldclock/" }

if ($opt_f) { $URL = "http://www.whattimeisit.com/cgitime.exe?Mode=FullList"
} else { $URL = "http://www.whattimeisit.com/cgitime.exe?Mode=FullList" }

# print "timeanddate.com:\n"; # legal
print "www.whattimeisit.com:\n";

system("wget -O $download $URL &>/dev/null");

open(CONT, $download) or die "Could not open $download";

while (<CONT>){
foreach $city(@ARGV) {
if ($city !~ /\w+/) { die "City '$city' not alphanumeric" }
if (/$city.+?(\d{1,2})\:(\d+\d+) ((AM|PM))/i) {
my ($hr, $min, $ampm) = ( $1, $2, $3);
my $newhr = twelveto24($hr, $ampm);
my $newtime = $newhr . ":" . $min;
my $F = 'A' . $displaywidth;
print pack("$F A5", $city, $newtime), "\n";
}
}
}

unlink $download;

Wow. I'm glad you did that, because I already spent much more than a few minutes on it before remembering things like DST...which would mean much more work than I even want to consider bothering with =o)
Code Sample
$ /opt/citytime.pl tokyo paris houston
Downloading time from http://www.timeanddate.com/worldclock/
tokyo 2:33
paris 19:33
houston 12:33

Now I'm well impressed - let's see if I can get this into torsmo

So, I added this to the end of .torsmorc:
Code Sample
${color red}$hr
${color grey}Tokyo: $color ${execi 180 ~/.citytime.pl Tokyo}

But, since it starts off with:
Quote
Tokyo: Getting time from http://www.timeanddate.com/worldclock

The torsmo display gets v-e-r-y w-i-d-e...

I guess for this to progress, I'd need a site that didn't require the url to be stated.

Next Page...
original here.