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

Using the two simple subs below I display each day in 2002. However the date October 27 occurs twice. When I combine the two subs into one, October 27 only comes up once. Any ideas as to why? joe budd
#!/usr/bin/perl use Time::Local; &do_year; sub do_year { my ($i, $date); for ($i=0; $i<12; $i++) { $date = timelocal(0, 0, 0, 1, $i, 2002); &do_month($date); } } sub do_month { my ($date_int) = @_; my ($month); my $day_int = (60 * 60 * 24); my @months = ("January", "February", "March", "April", "May", "Jun +e", "July", "August", "September", "October", "Novenber", "December") +; print"\n"; $month = (localtime($date_int))[4]; while ($month == (localtime($date_int))[4]) { print $months[$month], " ", (localtime($date_int))[3], " ", (( +localtime($date_int))[5]+1900), "\n"; $date_int += $day_int; } }

Replies are listed 'Best First'.
Re: Two Otober 27, 2002 using timelocal
by davorg (Chancellor) on Oct 15, 2001 at 18:54 UTC

    That wouldn't be the day that you leave daylight savings time would it?

    Try it again. but using midday instead of midnight in your call to timelocal.

      1) Yes I guess that it is the day we leave daylignt savings time.
      2) Midday overcomes that issue.
      3) I'm impressed.
      4) Thank you.

        To clarify what the problem is: your code assumes that any given day is 24 hours long - as we enter and leave DST that is not true.

        You may have been missing a day somw time in March as well :)

        --
        <http://www.dave.org.uk>

        "The first rule of Perl club is you don't talk about Perl club."

Re: Two Otober 27, 2002 using timelocal
by cfreak (Chaplain) on Oct 15, 2001 at 22:12 UTC

    Any day after the last sunday in october causes problems with daylight savings time. I got around it by adding one hour to the last sunday in october. You can find a similar problem in April.

    (Note: davorg's answer is probably the better one I subtracted the hour to get it to work right because I was doing stuff with the time in between)