Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Checking for leap year

by joshua (Pilgrim)
on Feb 20, 2002 at 03:22 UTC ( [id://146478]=CUFP: print w/replies, xml ) Need Help??

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Checking for leap year
by jryan (Vicar) on Feb 20, 2002 at 03:27 UTC

    Unfortunately, this isn't thorough. Leap years don't occur if the year is a centennial year (although they do occur every 4th century). Here is what we in some of the NMS scripts:

    sub is_leap { my $y = shift; return (!($y % 100) && !($y % 400)) || (($y % 100) && !($y % 4)); }
      It's probably easier to just write out what you mean:
      sub is_leap { my $y = shift; return 0 if $y % 4; # not multiple of 4 return 1 unless $y % 400; # is multiple of 400 return 0 unless $y % 100; # is multiple of 100 return 1; # everything else }

      -- Randal L. Schwartz, Perl hacker

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-20 16:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found