Click here to Skip to main content
Click here to Skip to main content

Leap Years

, , 20 Feb 2000
Rate this:
Please Sign up or sign in to vote.
A discussion on the thorny issue of leap years.

There has been a lot of interest about the correct method of calculating leap years lately, especially since it seems many programmers have got it wrong. Before Y2K the approximation "a leap year occurs every four years" was good enough for most situations. If you needed to deal with historical dates (post 1600AD), then you had to add the clause "unless the year was divisible by 100".

This is where many programmers left it - but the rule for the Gregorian calendar is:

  1. Most years divisible by 4 are Leap Years (i.e. 1996 was)
  2. However, most years divisible by 100 are NOT! (1900 was not)
  3. Unless they are also divisible by 400 (2000 will be)

It turns out though that there are even more subclauses that can be appended to these rules to take into account the fact that the Earth takes 365.2421898 days to orbit the sun (well, it did in 1996 - it's now a shade shorter than that). Because of this, the Gregorian calendar will be off by about a day in 3000 years or so. There are various proposals on how to deal with this, but it seems it won't really be an issue until 2800AD.

One proposal (by the astronomer John Herschel (1792-1871) among others) suggests

  • Every year which is divisible by 4000 is not a leap year.

This is more accurate than the Gregorian calendar, but has not been officially adopted.

Another proposal (by the Orthodox church in Greece) is to replace the "divisible by 400" rule by the following:

  • Every year which when divided by 900 leaves a remainder of 200 or 600 is a leap year.

This makes 1900, 2100, 2200, 2300, 2500, 2600, 2700, 2800 non-leap years, whereas 2000, 2400, and 2900 are leap years. This will not create a conflict with the rest of the world until the year 2800. However, this rule has also not been officially adopted.

Further reading:

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Authors

Chris Maunder
Founder CodeProject
Canada Canada
Chris is the Co-founder, Administrator, Architect, Chief Editor and Shameless Hack who wrote and runs The Code Project. He's been programming since 1988 while pretending to be, in various guises, an astrophysicist, mathematician, physicist, hydrologist, geomorphologist, defence intelligence researcher and then, when all that got a bit rough on the nerves, a web developer. He is a Microsoft Visual C++ MVP both globally and for Canada locally.
 
His programming experience includes C/C++, C#, SQL, MFC, ASP, ASP.NET, and far, far too much FORTRAN. He has worked on PocketPCs, AIX mainframes, Sun workstations, and a CRAY YMP C90 behemoth but finds notebooks take up less desk space.
 
He dodges, he weaves, and he never gets enough sleep. He is kind to small animals.
 
Chris was born and bred in Australia but splits his time between Toronto and Melbourne, depending on the weather. For relaxation he is into road cycling, snowboarding, rock climbing, and storm chasing.
Follow on   Twitter   Google+   LinkedIn

LeRoy Baxter

United States United States
No Biography provided

Comments and Discussions

 
GeneralMy vote of 5 PinmemberCIDev24-Sep-10 6:18 
GeneralOrthodox Church Pinmemberm00n120-Jul-10 3:51 
Questionhow about this Pinmembersimon.cropp9-Jul-07 18:39 
AnswerRe: how about this Pinmemberscottctr13-Jul-07 9:01 
AnswerRe: how about this PinadminChris Maunder13-Jul-07 9:02 
GeneralOops! PinmemberChris Hills2-May-05 6:39 
GeneralRe: Oops! PinadminChris Maunder10-Jul-07 2:48 
QuestionHas anyone seen gmttime() ? PinmemberBamaco229-Jan-04 8:10 
General...in other words Pinsussdixi16-Jul-00 12:04 
GeneralRe: ...in other words Pinmemberwulph10-Dec-03 13:56 
GeneralHistory PinsussMichael Krebs25-Feb-00 12:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 21 Feb 2000
Article Copyright 2000 by Chris Maunder, LeRoy Baxter
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid