Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Timelocal, Localtime Bug?

by alanonymous (Sexton)
on Mar 29, 2012 at 21:38 UTC ( [id://962484]=perlquestion: print w/replies, xml ) Need Help??

alanonymous has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks,

I may have found a bug but don't know how to tell...

With perl 5.8.4, I run this code and get:
use Time::Local; my $hour= 2; my $test = timelocal(0,0,$hour,1,3,2012); my @test2 = localtime($test); print "hour $hour vs $test2[2]\n";
hour 2 vs 2
If I run this identical code under perl 5.8.7, it outputs:
use Time::Local; my $hour= 2; my $test = timelocal(0,0,$hour,1,3,2012); my @test2 = localtime($test); print "hour $hour vs $test2[2]\n";
hour 2 vs 3
If I run this 2011 modified code under 5.8.7, it outputs:
use Time::Local; my $hour= 2; my $test = timelocal(0,0,$hour,1,3,2011); my @test2 = localtime($test); print "hour $hour vs $test2[2]\n";
hour 2 vs 2
Am I going crazy? What is going on?!? AHhhh!

-Alan

Replies are listed 'Best First'.
Re: Timelocal, Localtime Bug?
by JavaFan (Canon) on Mar 29, 2012 at 23:32 UTC
    5.8.7 isn't the latest release in the 5.8 series, there have been 2 more. Beside that, 5.8.x is no longer supported. 5.10.x is no longer supported either. I don't expect a new release in the 5.12 series to happen either.

    I suggest checking what your code does in 5.14, or in 5.15.9. If that prints what you think it should print, consider the bug to be fixed.

      The problem is that I am constrained to the installed version, and it would be a heck of a fight to get the administrators to update to a newer version.
        So, if there's a bug, and it got fixed, it would be utterly useless to you anyway?
Re: Timelocal, Localtime Bug?
by jwkrahn (Abbot) on Mar 29, 2012 at 21:53 UTC
    $ perl -le'my $test = localtime( 0, 0, $month, 1, 31, 2012 ); print $t +est' Too many arguments for localtime at -e line 1, near "2012 )" Execution of -e aborted due to compilation errors.

    Your code won't even compile, let alone run.

      It looks like it might run if you flip localtime and timelocal with each other (I'm guessing timelocal takes the arguments localtime is currently taking and vice-versa).

      That said, I have no idea concerning the original question. ><

        Sorry guys! My development machine is not connected to the internet, so I had to type the chunk of applicable code and I mixed up timelocal and localtime. I fixed the code samples in the original post, so now my original question actually applies (also put 3 instead of 31... I hate fat fingers today). Sorry!
Re: Timelocal, Localtime Bug?
by Riales (Hermit) on Mar 29, 2012 at 22:16 UTC

    This is from the documentation on Time::Local:

    $time = timelocal($sec,$min,$hour,$mday,$mon,$year);

    It looks like you're putting $month where $hour is supposed to go?

    EDIT: Nevermind, it looks like you're consistently checking the hours anyways. The 3 instead of 2 makes me think that it has something to do with DST (2 AM doesn't exist because we spring forward to 3 AM in the spring). Still, it doesn't happen on March 1st, so this doesn't seem quite correct...

      Sorry, I fixed the code chunk. I took it from my other machine and had fat fingers (mixing up localtime and timelocal...), so now with the code that's posted, the bug appears.
Re: Timelocal, Localtime Bug?
by thundergnat (Deacon) on Mar 30, 2012 at 14:29 UTC

    I would suspect that the version of Time::Local installed on your machine is older than version 1.13.

    From the changelog:

    1.13    2006-08-09
    
    ...
    
    - Fixed a bug that occurred around the DST change for Europe/London
      (and probably other time zones with a positive UTC offset). If
      given, the hour immediately after the change (2:00 AM for
      Europe/London), then the returned epoch was 3600 seconds too
      large. Reported by Roger Picton. See RT #11662.
    

      I dare say you've exactly found the bug I'm experiencing. Thanks for the help!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://962484]
Approved by lidden
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-24 20:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found