The day started with me having a conversation with a friend about how they celebrated a co-worker's "eleventh" birthday, his co-worker saying he'd be 12 except that there was no February 29th in 2000.
For someone born on February 29th, he knows surprisingly little about leap years. But the statement did make me double-check the code I was writing at work for a calendar control.
For those of you who are wondering, the way to determine a leap year is as follows:
- Is the year is divisible by 400? Then it's a leap year.
- Is the year divisible by 100 (but not 400)? It's not a leap year.
- Is the year divisible by 4 (but not 100)? It's a leap year.
Or simply stated:
bool IsLeapYear(int year)
{
return ((year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)));
}
(Yes, I first wrote more verbose code of nested IF statements, then reworked it to take in order of logical expressions to reduce it to one line)
On a side note:
I didn't realize there were also Leap Year traditions. For instance, "in the English speaking world, it is a tradition that women may propose marriage only on leap years." "The first documentation of this practice dates back to 1288, when Scotland passed a law that allowed women to propose marriage to the man of their choice in that year. They also made it law that any man who declined a proposal in a leap year must pay a fine. The fine could range from a kiss to payment for a silk dress or a pair of gloves." - [about.com]. Does that mean it's time to go get me some silk dresses?