Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Leap Year

by Agyeya (Hermit)
on May 17, 2004 at 10:22 UTC ( [id://353911]=note: print w/replies, xml ) Need Help??


in reply to How do I determine if a given year is a leap year?

The Date::Leapyear module will tell if a year is a (Gregorian) leap year:
use Date::Leapyear; if ( isleap(yyyy) ) { ... }
The function isleap(yyyy) returns 1 in a leap year, 0 otherwise.

Replies are listed 'Best First'.
Re: Answer: Leap Year
by idsfa (Vicar) on May 17, 2004 at 19:44 UTC

    And the source code for Date::Leapyear reads:

    sub isleap { my ($year) = @_; return 1 if (( $year % 400 ) == 0 ); # 400's are leap return 0 if (( $year % 100 ) == 0 ); # Other centuries are not return 1 if (( $year % 4 ) == 0 ); # All other 4's are leap return 0; # Everything else is not }

    which is already a provided answer. The same semi-correct formula is also used in Astro::Time and DateTime. Unless someone goes to the touble of encoding the entire FAQ, stick with the original answer. I like CPAN as much as the next Monk, but some modules are wasteful.

    Updated: I do note that the DateTime::Calendar::* modules at least make some attempt at dealing with cultural and temporal variances ...


    If anyone needs me I'll be in the Angry Dome.
      Yup. This was probably a pretty wasteful module.
      --
      Tommy Butler, a.k.a. TOMMY
      

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-03-29 06:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found