Update of /cvsroot/http-webtest/HTTP-WebTest-Plugin-DateTest/lib/HTTP/WebTest/Plugin
In directory usw-pr-cvs1:/tmp/cvs-serv30162/lib/HTTP/WebTest/Plugin
Modified Files:
DateTest.pm
Log Message:
Changed test result format and handling of time units
Index: DateTest.pm
===================================================================
RCS file: /cvsroot/http-webtest/HTTP-WebTest-Plugin-DateTest/lib/HTTP/WebTest/Plugin/DateTest.pm,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** DateTest.pm 12 Sep 2002 13:11:01 -0000 1.1.1.1
--- DateTest.pm 9 Oct 2002 22:15:16 -0000 1.2
***************
*** 7,11 ****
use vars qw($VERSION);
! $VERSION = '0.90';
=head1 NAME
--- 7,11 ----
use vars qw($VERSION);
! $VERSION = '0.91';
=head1 NAME
***************
*** 157,165 ****
}
my $age = ($pgdate) ? $now - $pgdate : 'unknown';
! my $ok = ($age ne 'unknown') && ($age < &_str2seconds($maxage));
push @results,
$self->test_result($ok,
! sprintf("%s %s %s (%s < %s)", $start, $datestr, $end, &_seconds2str($age), $maxage)
);
}
--- 157,166 ----
}
my $age = ($pgdate) ? $now - $pgdate : 'unknown';
! my ($maxsecs, $units) = &_str2seconds($maxage);
! my $ok = ($age ne 'unknown') && ($age < $maxsecs);
push @results,
$self->test_result($ok,
! sprintf("%s %s %s (%s > %s)", $start, $datestr, $end, &_seconds2str($age, $units), $maxage)
);
}
***************
*** 170,177 ****
}
! # look for trailing characters and interprete them as time unit
! sub _str2seconds {
! my $date = shift;
! my $TIMETAB = {
s => 1,
m => 60,
--- 171,177 ----
}
! sub TIMETAB {
! my $units = shift || '';
! my $tt = {
s => 1,
m => 60,
***************
*** 179,210 ****
d => 86400,
w => 604800,
! };
if ($date =~ /^\s*([\-+0-9.]+)\s*([smhdwSMHDW]).*/) {
! $date = $1 * $TIMETAB->{lc($2)};
} else {
$date =~ s/^\s*([\-+0-9.]+)\s*.*$/$1/g;
}
! return ($date =~ /^[\-+0-9.]/) ? $date : 0;
}
# convert seconds into time string
sub _seconds2str {
! my $date = shift;
my $str = '';
my $frag = 0;
! if ($frag = int($date / 604800)) {
$str .= "${frag}w ";
! $date -= $frag * 604800;
}
! if ($frag = int($date / 86400)) {
$str .= "${frag}d ";
! $date -= $frag * 86400;
}
! $frag = int($date / 3600);
$str .= sprintf "%02d:", $frag;
! $date -= $frag * 3600;
! $frag = int($date / 60);
$str .= sprintf "%02d:", $frag;
! $date -= $frag * 60;
$str .= sprintf "%02d", $date;
return $str;
--- 179,222 ----
d => 86400,
w => 604800,
! };
! return $tt->{$units};
! }
!
! # look for trailing characters and interprete them as time unit
! sub _str2seconds {
! my $date = shift;
! my $units = '';
if ($date =~ /^\s*([\-+0-9.]+)\s*([smhdwSMHDW]).*/) {
! $units = lc($2);
! $date = $1 * &TIMETAB($units);
} else {
$date =~ s/^\s*([\-+0-9.]+)\s*.*$/$1/g;
}
! $date = 0 unless ($date =~ /^[\-+0-9.]/);
! return wantarray ? ($date, $units) : $date;
}
# convert seconds into time string
sub _seconds2str {
! my ($date, $units) = @_;
! if (&TIMETAB($units)) {
! return sprintf("%4.2f %s", $date/&TIMETAB($units), $units);
! }
my $str = '';
my $frag = 0;
! if ($frag = int($date / &TIMETAB('w'))) {
$str .= "${frag}w ";
! $date -= $frag * &TIMETAB('w');
}
! if ($frag = int($date / &TIMETAB('d'))) {
$str .= "${frag}d ";
! $date -= $frag * &TIMETAB('d');
}
! $frag = int($date / &TIMETAB('h'));
$str .= sprintf "%02d:", $frag;
! $date -= $frag * &TIMETAB('h');
! $frag = int($date / &TIMETAB('m'));
$str .= sprintf "%02d:", $frag;
! $date -= $frag * &TIMETAB('m');
$str .= sprintf "%02d", $date;
return $str;
|