#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    7
    Rep Power
    0

    Issue with timelocal(), doesn't like today's date.


    Can anyone see what the problem is here:

    I'm feeding timelocal a valid date: 2013-10-31 14hrs 50min, 44sec. This code has been working fine until today and the date being 31 October.

    Code:
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
    
    debug("  today  = sec=$sec,min=$min,hour=$hour,day=$mday,month=$mon,year=$year,weekday=$wday,yearday=$yday,isdst=$isdst");
    
    my $epoch  = timelocal(1, $min, $hour, $mday, $mon + 1, $year + 1900); # Line 986
    
    Thu Oct 31 14:50:44 2013:   today  = sec=44,min=50,hour=14,day=31,month=9,year=113,weekday=4,yearday=303,isdst=1
    Day '31' out of range 1..30 at ./Test.pl line 986
    
    I then tried using timelocal_nocheck:
    
    use Time::Local 'timelocal_nocheck';
    
     my $epoch  = timelocal_nocheck(1, $min, $hour, $mday, $mon + 1, $year + 1900);
    
    Undefined subroutine &main::timelocal called at ./Test.pl line 988.
    I've also tried the following:

    Code:
     my $epoch  = timelocal(44, 55, 14, 31, 10, 2013);
    Same result. Day 31 out of range.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    7
    Rep Power
    0
    Originally Posted by rhugga
    Can anyone see what the problem is here:

    I'm feeding timelocal a valid date: 2013-10-31 14hrs 50min, 44sec. This code has been working fine until today and the date being 31 October.

    Code:
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
    
    debug("  today  = sec=$sec,min=$min,hour=$hour,day=$mday,month=$mon,year=$year,weekday=$wday,yearday=$yday,isdst=$isdst");
    
    my $epoch  = timelocal(1, $min, $hour, $mday, $mon + 1, $year + 1900); # Line 986
    
    Thu Oct 31 14:50:44 2013:   today  = sec=44,min=50,hour=14,day=31,month=9,year=113,weekday=4,yearday=303,isdst=1
    Day '31' out of range 1..30 at ./Test.pl line 986
    
    I then tried using timelocal_nocheck:
    
    use Time::Local 'timelocal_nocheck';
    
     my $epoch  = timelocal_nocheck(1, $min, $hour, $mday, $mon + 1, $year + 1900);
    
    Undefined subroutine &main::timelocal called at ./Test.pl line 988.
    I've also tried the following:

    Code:
     my $epoch  = timelocal(44, 55, 14, 31, 10, 2013);
    Same result. Day 31 out of range.
    Never mind... bonehead mistake. timelocal uses months that start with 0 and an unadjusted year (ie: no $year + 1900)

    /bonk.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    843
    Rep Power
    496
    Originally Posted by rhugga
    timelocal uses months that start with 0
    From your first post, I was immediately looking for this type of mistake, but it looked like you used 09 for October, so this seemed to be correct. I therefore don't quite understand the problem you had. But the formatting of your post was, let's say, not optimal, maybe I missed something.

IMN logo majestic logo threadwatch logo seochat tools logo