Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Your skill will accomplish
what the force of many cannot
 
PerlMonks

How do I determine if a given year is a leap year?

 | Log in | Create a new user | The Monastery Gates | Super Search | 
 | Seekers of Perl Wisdom | Meditations | PerlMonks Discussion | 
 | Obfuscation | Reviews | Cool Uses For Perl | Perl News | Q&A | Tutorials | 
 | Poetry | Recent Threads | Newest Nodes | Donate | What's New | 

( #32583=categorized question: print w/ replies, xml ) Need Help??
Contributed by Adam on Sep 15, 2000 at 02:48 UTC
Q&A  > dates and times


Answer: Leap Year
contributed by Adam

The leap year formula is:

A leap year is divisable by 4, but not by 100 (except if divisable by 400.)

if( 0 == $year % 4 and 0 != $year % 100 or 0 == $year % 400 ) { # Then $year is a leap year. }
Answer: Leap Year
contributed by Agyeya

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.
Answer: Leap Year
contributed by mojotoad

DateTime offers an is_leap_year method for datetime objects.

They also provide leapsecond information via the DateTime::LeapSecond class, if you're into that.

Matt

Answer: Leap Year
contributed by TheHobbit

Well, may be... but your answer is false:).

Let's be precise: nowadays, your answer is right, but only since Gregorian reform, which has been take into account at different times in differents countries. Before that, and since 45BC, there was a leap year in every year divisible by 4 (NOTE: 45BC is year -44).

Even that isn't exatly true... At the beginning people did not understand what "once in 4 years" meant, and there was a period (between 45BC and 9BC) where there was a leap year every 3 years. Followed by a period (between 8BC and 8AD) where there was no leapyear at all.

See the Calendar FAQ .


TheHobbit
Answer: Leap Year
contributed by Sol-Invictus

The exact dates when countries (that use the Western calendar) adopted the Gregorian version varies. See this section of the Calendar FAQ

Please (register and) log in if you wish to add an answer



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Login:
    Password
    remember me
    What's my password?
    Create A New User

    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (25)
    BrowserUk
    Corion
    GrandFather
    Your Mother
    toolic
    holli
    Gavin
    atcroft
    kennethk
    MidLifeXis
    thezip
    Eyck
    pileofrogs
    clinton
    socketdave
    lima1
    Utilitarian
    lostjimmy
    mje
    ssandv
    RyuMaou
    MikeDexter
    smile4me
    im2
    plieberg
    As of 2010-02-09 20:10 GMT
    Sections?
    The Monastery Gates
    Seekers of Perl Wisdom
    Meditations
    PerlMonks Discussion
    Categorized Q&A
    Tutorials
    Obfuscated Code
    Perl Poetry
    Cool Uses for Perl
    Perl News
    Information?
    PerlMonks FAQ
    Guide to the Monastery
    What's New at PerlMonks
    Voting/Experience System
    Tutorials
    Reviews
    Library
    Perl FAQs
    Other Info Sources
    Find Nodes?
    Nodes You Wrote
    Super Search
    List Nodes By Users
    Newest Nodes
    Recently Active Threads
    Selected Best Nodes
    Best Nodes
    Worst Nodes
    Saints in our Book
    Leftovers?
    The St. Larry Wall Shrine
    Offering Plate
    Awards
    Craft
    Snippets Section
    Code Catacombs
    Quests
    Editor Requests
    Buy PerlMonks Gear
    PerlMonks Merchandise
    Planet Perl
    Perlsphere
    Use Perl
    Perl.com
    Perl 5 Wiki
    Perl Jobs
    Perl Mongers
    Perl Directory
    Perl documentation
    CPAN
    Random Node
    Voting Booth?

    What level of existential comfort do you require?

    Palace
    Executive suite at the best hotel
    Regular hotel in a decent part of town
    Motel
    Boarding house
    Sleeping Bag on Couch in Basement
    Any port in a storm
    Camping under the freeway overpass
    Jail
    Other

    Results (279 votes), past polls