This node falls below the community's minimum standard of quality and will not be displayed.

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