Time-Local - Re: Day '31' out of range 1..30

Posted on Tue Sep 19 00:36:11 2006 by methylal in response to 2881 (See the whole thread of 3)
Re: Day '31' out of range 1..30
Looking at the module:

You will see that Months are set in an array:
my @MonthDays = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

Therefore, when it tries to pull the number of days for the month you passed to it, it's searching it's index from 0 to 11. So when you pass in your Month as 10 (October), it's searching the array and thinking only 30 days are avilable and failing when you specify 31 since you are technically 'out of range'.

Three solutions:
1) Subtract 1 from your month before passing it into the Time::timelocal method
2) Just open up your Local.pm file and in the subroutine (timegm), look for the following:
my $md = $MonthDays[$month];
and subtract 1 from $month... so:
my $md = $MonthDays[$month-1];
3) Use DateTime::Precise instead.

--meth
Write a response