Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi
I have to deal with TimeZones and I'd like to use Time::ParseDate.
As I've got wrong results I herewith paste my little program that tries
to deal with an ebay-site that has two times: PST and MEZ and it
show a difference of only 3600 seconds (1 hour)?

Am I doing s.th wrong? Or is it a bug?

Thanks for your effort, I appreciate your 'service' allway when I came here! Best wishes to all for 2005 Carl
PS:I think you can copy, paste, and run it (hopefully)
#! /usr/bin/perl use LWP::Simple; use LWP::UserAgent; use Time::ParseDate; use Time::Zone; my $GETTIMELIMIT = 30; # official eBay-Time: PST and MEZ my $url = 'http://cgi3.ebay.de/aw-cgi/eBayISAPI.dll?TimeShow'; my @L = ladeEbay( $url ); # print "loaded:\t",scalar @L,"\n"; %time = ( myTime => tz_local_offset() ); print "\n"; while ( @L) { my $l = shift(@L); if ( $l =~ s/(\(eBay\-Zeit\))//) { $l =~ s/^(.+?>)//g; $l =~ s/(<.+?>)/ /g; #print "\nzeit1:\t$l\n"; my @i = split /[\s,\.]+/, $l; #print join '; ', @i, "\n\n"; #$i[0] = "$2 $1 $3" if ($i[0] =~ /(\w+)[\s-](\d+)[\s-](\d+)/); my @i = split /[\s,\.]+/, $l; $time{usaDay} = "$i[4] $i[5] $i[6]"; $i[7] =~ s/://g; #hhmmss[[AP]M] $i[7] .= ($i[7] lt '120000' ) ? ' AM':' PM'; $time{usaTime} = $i[7]; $time{usaTiZo} = $i[8]; $time{usaOFF} = tz_offset($i[8]); next; } if ( $l =~ s/(<B>eBay\s*Deutschland)//) { $l =~ s/^(.+?>)//g; $l =~ s/(<.+?>)/ /g; #print "zeit2:\t$l\n"; my @i = split /[\s,\.]+/, $l; #print join '; ', @i, "\n\n"; my @i = split /[\s,\.]+/, $l; $time{brdDay} = "$i[2] $i[3] $i[4]"; $i[5] =~ s/://g; #hhmmss[[AP]M] $i[5] .= ($i[5] lt '120000' ) ? ' AM':' PM'; $time{brdTime} = $i[5]; $time{brdTiZo} = $i[6]; $time{brdOFF} = tz_offset($i[6]); last; } } $time{difOFF} = $time{brdOFF} - $time{usaOFF}; $time{usaSec} = parsedate($time{usaDay}.' '.$time{usaTime}, ZONE => $t +ime{usaTiZo}); $time{brdSec} = parsedate($time{brdDay}.' '.$time{brdTime}, ZONE => $t +ime{brdTiZo}); $time{diTime} = $time{brdSec} - $time{usaSec}; foreach (sort keys %time) { print "\t$_ => \t$time{$_}\n"; } print "\n"; sub ladeEbay { my $s; eval { local $SIG{ALRM} = sub { die "Zeit_Limit $!"}; alarm($GETTIMELIMIT); # 30 Sekunden = 0.5 min für ein get my $ua = LWP::UserAgent->new; my $req = HTTP::Request->new(GET => $url); $s = $ua->request($req)->as_string; alarm(0); }; if ($@ and ($@ =~ /Zeit_Limit/) ) {# da steht u.a. "Zeit_Limit" dr +in $ERRORMAIL .="TIMEOUT, NIX GELADEN (30 sec): $@\n"; alarm(0); return; } $s =~ s/\x0A|\x0D//g; return split /<table|<td|<tr/i, $s; }

Replies are listed 'Best First'.
Re: TimeZone Error?
by Anonymous Monk on Jan 04, 2005 at 12:12 UTC
    Remark: acc. to Time::ParseDate thoes four lines should not be needed.
    I inserted them as I thought that there is a bug
    in determine 2 AM and 2 PM (=14).
    So I got the same results if I eliminate these lines
    (even blank or not before APM doesn't matter):
    # 1st if ... $i[7] =~ s/://g; #hhmmss[[AP]M] $i[7] .= ($i[7] lt '120000' ) ? ' AM':' PM'; # 2nd if.. $i[5] =~ s/://g; #hhmmss[[AP]M] $i[5] .= ($i[5] lt '120000' ) ? ' AM':' PM';
    Carl
Re: TimeZone Error?
by aquarium (Curate) on Jan 04, 2005 at 14:02 UTC
    PST = UTC - 8 MEZ = UTC + 1 .. so a difference of 9 hours. Is this what you get?
    the hardest line to type correctly is: stty erase ^H
      Well, no!
      This ebay site shows at the same moment the time in Europe and in USA/Pacific,
      so there should not be any difference! Beside that, while
      $time{brdTi1} = scalar localtime($time{brdSec}); $time{brdTi2} = scalar localtime($time{brdSec}-$time{brdOFF});
      shows exact time for MEZ:
      brdDay => 05 Jan 2005 brdTime => 09:50:04 brdOFF => 3600 brdSec => 1104918604 brdTi1 => Wed Jan 5 10:50:04 2005 brdTi2 => Wed Jan 5 09:50:04 2005 brdTiZo => MEZ
      the same code:
      $time{usaTi1} = scalar localtime($time{usaSec}); $time{usaTi2} = scalar localtime($time{usaSec}-$time{usaOFF});
      for PST shows this:
      usaDay => 05 Jan 2005 usaTime => 00:50:04 usaOFF => -28800 usaSec => 1104915004 usaTi1 => Wed Jan 5 09:50:04 2005 usaTi2 => Wed Jan 5 17:50:04 2005 usaTiZo => PST
      Any Ideas?
      Carl
        is this ebay website yours or someone elses? it has the wrong concept of timezones if it's only showing an hour difference between MEZ and PST. it's definitely more than an hour time difference between Europe and Central America.
        the hardest line to type correctly is: stty erase ^H