Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Determining the dayname for the last day of any given month

by ikegami (Patriarch)
on Jun 20, 2006 at 15:40 UTC ( [id://556433]=note: print w/replies, xml ) Need Help??


in reply to Re: Determining the dayname for the last day of any given month
in thread Determining the dayname for the last day of any given month

Not all days are 24*60*60 seconds long, and $m suffers from off-by-one errors. Fix:

my ($y, $m) = ($year-1900, $month-1); # Day before the first of next month: my $last = timelocal_nocheck(0, 0, 0, 1-1, $m+1, $y);

You'll need to import timelocal_nocheck from Time::Local

Updated. However, the fixed code doesn't work because timelocal_nocheck doesn't handle $m+1 as I expect.

Replies are listed 'Best First'.
Re^3: Determining the dayname for the last day of any given month
by davorg (Chancellor) on Jun 20, 2006 at 15:52 UTC
    Not all days are 24*60*60 seconds long

    Well the ones on the first of the month all are :)

    But you're right, they aren't guaranteed to _always_ be. The easiest fix is probably to change the call to timelocal so it uses midday rather than midnight.

    $m suffers from off-by-one errors

    I don't think it does. The value you get from the user is in the range 1-12. We want the next month, but timelocal wants the number in the range 0-11. So we already have the correct number (except we need to do some adjustment if the month is 12). It might not be the clearest algorithm in the world, but it _is_ correct.

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

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      We want the next month

      Duh! Of course!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-03-19 03:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found