davidbi
asked on
Problems with timelocal
Hi all;
I've inherited some PERL scripts that produce the reports for our Netbackup daily processes. This is running on a Windows 2003 SP1 Standard edition server. One of the reports quit working July 18, 2007. I ran the script from the command line and received the error:
Month '-1' out of range 0..11 at LP_Date.pm line 214
The sub that line 214 is in is as follows:
#########
# this subroutine is given a human-readable
# date (MM/DD/YY HH:MM:SS) and returns the
# equivalent epoch-style date (10 digits,
# seconds since 1970)
# e.g. if it is passed "02/12/99 00:00:17",
# it will return "0918799217"
#########
sub time2stamp {
use Time::Local;
my ($time) = @_;
($tmp_date,$tmp_time) = split / /, $time, 2;
($tmp_month,$tmp_day,$tmp_ year) = split /\//, $tmp_date, 3;
($tmp_hour,$tmp_min,$tmp_s ec) = split /:/,$tmp_time, 3;
$stamp = timelocal($tmp_sec,$tmp_mi n,$tmp_hou r,$tmp_day ,$tmp_mont h-1,$tmp_y ear);
return $stamp;
}
I removed the -1 and received the error:
Day '' out of range 1..31 at LP_Date.pm line 214
Line 214 is $stamp = timelocal($tmp_sec,$tmp_mi n,$tmp_hou r,$tmp_day ,$tmp_mont h-1,$tmp_y ear);
This is part of a larger module, but this is where the error is occurring. I would appreciate any enlightenment to what the problem is.
I've inherited some PERL scripts that produce the reports for our Netbackup daily processes. This is running on a Windows 2003 SP1 Standard edition server. One of the reports quit working July 18, 2007. I ran the script from the command line and received the error:
Month '-1' out of range 0..11 at LP_Date.pm line 214
The sub that line 214 is in is as follows:
#########
# this subroutine is given a human-readable
# date (MM/DD/YY HH:MM:SS) and returns the
# equivalent epoch-style date (10 digits,
# seconds since 1970)
# e.g. if it is passed "02/12/99 00:00:17",
# it will return "0918799217"
#########
sub time2stamp {
use Time::Local;
my ($time) = @_;
($tmp_date,$tmp_time) = split / /, $time, 2;
($tmp_month,$tmp_day,$tmp_
($tmp_hour,$tmp_min,$tmp_s
$stamp = timelocal($tmp_sec,$tmp_mi
return $stamp;
}
I removed the -1 and received the error:
Day '' out of range 1..31 at LP_Date.pm line 214
Line 214 is $stamp = timelocal($tmp_sec,$tmp_mi
This is part of a larger module, but this is where the error is occurring. I would appreciate any enlightenment to what the problem is.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I'm guessing you are passing it an invalid date then.
For debugging, try this:
sub time2stamp {
use Time::Local;
my ($ht) = @_;
print "time2stamp: $ht\n";
return 0 unless $ht =~ /(\d+)\/(\d+)\/(\d+)\s+(\d +):(\d+):( \d+)/;
my $stamp = timelocal($6,$5,$4, $2,$1-1,$3);
return $stamp;
}
what is the output with the above?
For debugging, try this:
sub time2stamp {
use Time::Local;
my ($ht) = @_;
print "time2stamp: $ht\n";
return 0 unless $ht =~ /(\d+)\/(\d+)\/(\d+)\s+(\d
my $stamp = timelocal($6,$5,$4, $2,$1-1,$3);
return $stamp;
}
what is the output with the above?
ASKER
Just re-ran with the modification to the sub and it worked! I think I ran the the old script on the other server, running the modifications that you did has worked. Thank you very much.
What was the date that was passed to the sub, and what would you want it to return in that case?
ASKER