Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by ikegami (Pope)
on Jun 20, 2006 at 15:40 UTC ( #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.


Comment on Re^2: Determining the dayname for the last day of any given month
Select or Download Code
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
Node Status?
node history
Node Type: note [id://556433]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2014-07-31 05:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (245 votes), past polls