?
Solved

Problems with timelocal

Posted on 2007-07-24
5
Medium Priority
?
243 Views
Last Modified: 2011-09-20
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_sec) = split /:/,$tmp_time, 3;

$stamp = timelocal($tmp_sec,$tmp_min,$tmp_hour,$tmp_day,$tmp_month-1,$tmp_year);
 
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_min,$tmp_hour,$tmp_day,$tmp_month-1,$tmp_year);

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.
0
Comment
Question by:davidbi
  • 2
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
Adam314 earned 2000 total points
ID: 19558311
sub time2stamp {
      use Time::Local;
      my ($ht) = @_;
      "02/12/99 00:00:17"
      return 0 unless $ht =~ /(\d+)\/(\d+)\/(\d+)\s+(\d+):(\d+):(\d+)/;
      my $stamp = timelocal($6,$5,$4, $2,$1-1,$3);
       
       return $stamp;
}
0
 

Author Comment

by:davidbi
ID: 19558917
Thanks for the response Adam314; I re-ran the script and still get the same error, would it help if I posted the whole module?
0
 
LVL 39

Expert Comment

by:Adam314
ID: 19559067
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?
0
 

Author Comment

by:davidbi
ID: 19559219
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.
0
 
LVL 85

Expert Comment

by:ozo
ID: 19565817
What was the date that was passed to the sub, and what would you want it to return in that case?
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, I had the need to build a standalone system to run a point-of-sale system. I’m running this on a low-voltage Atom processor, so I wanted a light-weight operating system, but still needed Windows. I chose to use Microsoft Windows Server 200…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question