How to manually calculate leap year?
The recent leap year bug in the PS3 reminds me of a basic programming exercise I did when I was in poly year 1. For the exercise, we were told to write an algorithm to validate dates. It is fairly straight forward for all the month except February because of the leap year.
The Gregorian calendar, which most of the countries are currently using, has this leap year thing which confuses some programmers. Leap year is a year when February has 29 days instead of 28 days.
Actually, the logic is very simple. If the year is divisible by 4, it is a leap year. But if the year can be divisible by 100, it will not be a leap year unless it can also be divisible by 400.
Which means the year 2000 is a leap year. But 1900 and 2100 are not leap year. 2008 and 2012 are leap year.
By the way, anyone got any idea how to validate Chinese Lunar Calendar? I think the lunar calendar is much more complicated. There are some years when they repeat the entire month.
Update: Just notice that the Singtel mioTV glitch also happened on 1st March. Could it be the leap year bug also?
Related posts:





