Tech

All things technology

Lifestyle

This is life

Current affairs

The real world

Personal

Just me

Random

Totally random stuff

Home » Uncategorized

How to manually calculate leap year?

Submitted by on March 5, 2010 – 2:30 PMNo Comment | 4 views

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:

  1. Leap Day
  2. The leap second
  3. Table Calendar
  4. Review of my 2007 New Year Resolution
  5. End of the world has been postponed till next year




Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.

CommentLuv badge