[sf-perl] localtime bug
Ray Baxter
ray at warmroom.com
Thu Apr 13 00:52:30 PDT 2006
S A wrote:
> Anyone else have trouble with localtime behaving funny? For some odd
> reason Time::Local is an hour off when it interprets this particular set of
> numbers
>
> [samshey at amshey samshey]$ cat test
> #!/usr/local/bin/perl -w
>
> use strict;
> use Time::Local;
>
> #timelocal($secs, $mins, $hrs, $day, $month, $year)
> my $time_start = timelocal(40, 59, 03, 02, 03, 06); # 3:59:40
> my $time_end = timelocal(33, 00, 04, 02, 03, 06); # 4:00:33
>
> print "localtimes:\n";
> print "timelocal start: $time_start (= " . localtime($time_start) . ")\n";
> print "timelocal end: $time_end (= " . localtime($time_end) . ")\n";
>
> print "gm times:\n";
> print "timelocal start: $time_start (= " . gmtime($time_start) . ")\n";
> print "timelocal end: $time_end (= " . gmtime($time_end) . ")\n";
>
> exit;
> [samshey at amshey samshey]$ perl test
> localtimes:
> timelocal start: 1143979180 (= Sun Apr 2 04:59:40 2006)
> timelocal end: 1143975633 (= Sun Apr 2 04:00:33 2006)
> gm times:
> timelocal start: 1143979180 (= Sun Apr 2 11:59:40 2006)
> timelocal end: 1143975633 (= Sun Apr 2 11:00:33 2006)
>
If you initialize timelocal using either a three-, or four-digit year,
the results are correct.
Try either
my $time_start = timelocal(40, 59, 03, 02, 03, 2006);
my $time_start = timelocal(40, 59, 3, 2, 3, 106);
I believe this is another instance of a reported bug, with the opposite
http://rt.cpan.org/Public/Bug/Display.html?id=11662
Ray
More information about the SanFrancisco-pm
mailing list