Happy Leap Day!

Posted by on in Blogs
It's Leap Day, February 29th.  An extra day this year for all of us to get more done.  The US National Institute of Standards and Technology leap year FAQ page describes a Leap Year, Leap Second, and even the possibility of a Negative Leap Second.  There is even an Honor Society of Leap Year Babies home page. Time and date.com discusses why leap years are used.

Leap year programming algorithms are one of the classic Computer Science programs that we all had to write.  It's amazing that some developers still make mistakes (hint: pay attention to century years divisible evenly by 400).  Here is the implementation of the Delphi/RAD Studio IsLeapYear function (from the SysUtils.pas source file):
function IsLeapYear(Year: Word): Boolean;
    Result := (Year mod 4 = 0) and ((Year mod 100 <> 0) or (Year mod 400 = 0));

Here are a few additional Leap Year algorithms and functions in different languages.  Enjoy your extra day this year.  At CodeGear, in Scotts Valley, we are having a Leap Day party this afternoon.  I hope you are all enjoying your day as well.







Gold User, Rank: 1, Points: 2466
David Intersimone (known to many as David I.) is a passionate and innovative software industry veteran-often referred to as a developer icon-who extols and educates the world on Embarcadero developer tools. He shares his visions as an active member of the industry speaking circuit and is tapped as an expert source by the media. He is a long-standing champion of architects, developers and database professionals and works to ensure that their needs are folded into Embarcadero's strategic product plans. David holds a bachelor's degree in computer science from California Polytechnic State University at San Luis Obispo, California.


  • Guest
    Thomas Mueller Thursday, 28 February 2008

    Leap years are easy, but do you know how to calculate the week of the year? How is it defined? OK, even that is easy nowadays, there is the Internet to look it up. I guess that shows my age....

  • Guest
    Richard Foersom Friday, 29 February 2008

    Leap years are difficult stuff ;-), take MS Excel as example. Excel use date numbering starting from 1900-01-01 as day 1.

    Try this:
    - Open MS Excel on a PC, any version will do
    - Format a cell as date format
    - Enter 60 as day number

    Result: A non existing day at the end of February 1900!

    BTW, according to MS there were also a day 0 in January 1900.

    OpenOffice Calc is compatible with the Excel numbering scheme, but only from 1900-03-01 onwards.

  • Guest
    Anders E. Andersen Sunday, 2 March 2008

    Not so fast Sirs! In Denmark the actual leap day is the 24th, not the 29th. This has no other practical significance, than where the note should be on the calender. :)

  • Guest
    Simon Monday, 10 March 2008

    IsLeapYear is a good example for novice programming.

    It may be greatly improved.

    see http://qc.borland.com/wc/qcmain.aspx?d=40715

  • Please login first in order for you to submit comments
  • Page :
  • 1

Check out more tips and tricks in this development video: