| Read about this in The Register. | | See our press release. |
| Why we published this code |
| Two things happened in 2007: | | 1) Microsoft started to pressure
technology policy makers around the world to accept their version of
the calender, which says 1900 is a Leap Year. | | 2) We found out that Toys R Us will not
send birthday cards to children if they are born on Leap Day. Their computers aren't programmed properly, so they can't. | Being
recognized champions of Leap Day awareness, we felt we had a duty to
show computer programmers the 4 lines of code required to test for Leap
Year. Microsoft could use this code to determine that 1900 is not
a Leap Year. Toys R Us could use this code to deterimine that the
current year is not a Leap Year, so the Feb 29 birthday card
can be started as soon as the Feb 28 birthday card completes.
|
|
| A Leap Year has 366 days. |
| The
code is written in PERL -- we'd like to offer the code in other
languages, but we're not programmers. So if you will translate this
code to your favorite language, we will post it here. Just send us an email with the code. |
| NOTE:
We've been advised that our code could be written better, and we don't
even spell Perl correctly... so for a better way to determine days in
year, in Perl, read this. |
Desciription The days in year diy(year)
function returns the number of days in any given year of the gregorian
calendar (i.e. 1583 through the present, and until the calendar is changed again).
It is a Leap Year if there are 366
days in the year.
The code:
sub diy($)
{ my $y = shift; $y % 4 && return 365; $y % 100 || $y % 400 && return 365; return 366;
}
my isLeapYear = 366 == diy(year); | |
Comments: Sorry
for the lack of comments. To us Leapers, this code is "self
documenting". You might think it could be improved, but
hey... we're not a software house -- we're a birthday club and the
only thing we really care about is that the little Leapers
get a birthday card every year. Here's how it works:
| 1) | Divide year by 4, if there's a remainder, the year has 365 days. | | 2) | Divide year by 100, if there's no remainder, then... Divide year by 400, if there's a remainder, the year has 365 days. | | 3) | If you get this far, year is a leap year, it has 366 days. |
| | Why do we care so much about this? Because, to
a child, there is no acceptable explanation for not receiving
a birthday card. Like computer
programmers, children are not Leap Day conscious. If a
computer programmer doesn't understand Leap Day, why would you expect a
child to? That's why a child should receive a birthday card, regardless
what date they are born, even if they're born on February 29th. |
|