Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (7) </ 1 [2] 3 4 5 6 7 ... >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: Looking for World Time Application, Anybody know of a good one?< Next Oldest | Next Newest >
WDef Offline





Group: Members
Posts: 798
Joined: Sep. 2005
Posted: Sep. 23 2007,15:29 QUOTE

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?
Back to top
Profile PM 
WDef Offline





Group: Members
Posts: 798
Joined: Sep. 2005
Posted: Sep. 23 2007,16:11 QUOTE

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;
Back to top
Profile PM 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Sep. 23 2007,16:30 QUOTE

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)

--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
Juanito Offline





Group: Members
Posts: 1601
Joined: Sep. 2005
Posted: Sep. 23 2007,17:36 QUOTE

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
Back to top
Profile PM 
Juanito Offline





Group: Members
Posts: 1601
Joined: Sep. 2005
Posted: Sep. 24 2007,11:07 QUOTE

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.
Back to top
Profile PM 
30 replies since Sep. 23 2007,11:40 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (7) </ 1 [2] 3 4 5 6 7 ... >/
reply to topic new topic new poll
Quick Reply: Looking for World Time Application

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code