[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: perl leap year function?



-----BEGIN PGP SIGNED MESSAGE-----

On Wed, 1 Sep 1999, Aaron Van Couwenberghe wrote:

>   I need an algorithm that can match a number of days with any month. For
> this to be useful, I need a function that can tell me if it's a leap year
> this year.

Just throwing one more subroutine onto the fire... It doesn't work with
years before 0, and IIRC it'll go wrong in 5048 or whenever the next
adjustment is needed.

sub isLeapYear{
    my $year=shift || die "&isLeapYear needs a year as input!\n";
    $year =~ /^\d/ || die "&isLeapYear needs a number as input!\n";
    $year % 400 or return 1;
    $year % 100 or return 0;
    $year % 4   or return 1;
    return 0;
}


- -- 
  finger for PGP public key.

-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: noconv

iQCVAwUBN82UDb7M/9WKZLW5AQF/GgQAmepoO1D+aj8Ib8UejtGJ7Odu+m2tuBR+
NQcFN5BzVOS2SGs0xYV0INrwuRhcK28Jio0tWuDBIQxVVSexjSV0kxev7L156bxL
02sEOYIDncNRonKqGofOFkASAvxHUsPxQlXZdFjEYyor44N/vOqrE/XnfVjXq0rH
rYFILiEpOrk=
=UMsC
-----END PGP SIGNATURE-----


Reply to: