February 2004 was an unusual leap year. There were 5 Sundays. I found myself wondering how often this happens, and also wondered what mathematical formula could be used to figure out how often it happened.

My first guess was that it happened every 24 years. My reasoning was that it takes 4 years to have a leap year, and dates are repeated every 6 years — i.e. if March 1 is a Monday in 2004, then it will be again in 2010.

That reasoning, however, turns out to be wrong. Or it is correct, but for only a short period of time.

     March 2004
Su Mo Tu We Th Fr Sa
    1  2  3  4  5  6
 7  8  9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31

     March 2010
Su Mo Tu We Th Fr Sa
    1  2  3  4  5  6
 7  8  9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31

     March 2016
Su Mo Tu We Th Fr Sa
       1  2  3  4  5
 6  7  8  9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

     March 2022
Su Mo Tu We Th Fr Sa
       1  2  3  4  5
 6  7  8  9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

As you can see, my little 6-year rule is sometimes true (true for 2004 and 2010, and true for 2016 and 2022, but false for 2010 and 2016, etc).

I quickly gave up and resorted to my copy of ACT! for Palm. I went back and saw that 1976, 1948, and 1920 were also leap-years with 5 Sundays. At that point I concluded that the formula was that we have a 5-Sunday-February every 28 years. (My original guess of 24 years was close, but off my one 4-year period.) That was the end of that.

Except that I kept wondering about it. I kept thinking of exceptions to the “every 4 years is a leap year rule” where I vaguely remembered people arguing about whether or not 2000 a.d. was going to be a leap year, and some software bug that thought 1900 was a leap year when it wasn’t supposed to be.

Being curious to see how far back this would hold, I ran a simple shell script:

#!/bin/sh

touch leapyear.txt

# start at this year
year=2004

# count back to 1850
while [ "$year" -gt "1850" ];
do
# output the calendar for Feb of each year
cal 02 $year >> leapyear.txt

# Subtract 4 (which should give us the previous leap year)
count=`expr $year - 4`
done

So once I was back at my laptop, I set out to research it out more fully. I quickly realized that my “every 28 years is a 5-Sunday-February” was also false — or true with some exceptions.

This simply counted backwards 4 years from 2004 to 1850 and gave me a calendar for February of that year. I simply read the ‘leapyear.txt’ file and saw that 1976, 1948, 1920, 1880, and 1852 were all 5-Sunday-Februarys (Februaries?). The 28-year rule works — to a point. You’ll notice a 40 year gap between 1880 and 1920. Part of that has to do with the oddity of the leap year system and years which are exactly divisible by 100 but not exactly divisible by 400. (So 1900 a.d. was not a leap year, but 2000 was.)

    February 1900
Su Mo Tu We Th Fr Sa
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28

Now I was really curious. How many other exceptions where there? How could I check? The simple “look through the file and see” method worked for 100 years (only 25 leap Februarys to examine) but it would be far less useful with a large dataset. For example, if I wanted to find all the 5-Sunday-Februarys from the year 1000 a.d. to 3000 a.d. it would take quite a long time to go through it manually. No, what I needed was a better script. The script should automatically check whether the 29th of Feburary is a Sunday or not. So I wrote another script (actually I just re-wrote the previous one):

#!/bin/sh

# what year do we want to start
year=1000

# what year do we want to end
endyear=3000

# Delete and recreate the output file
# so we have a clean start each time
rm leapyear.txt
touch leapyear.txt

# Enter loop, and continue as long as the year
# we are looking at is less than the year we want to end
while [ "$year" -lt "$endyear" ];
do
# Since this will take some time, we output
# the current year to STDOUT
echo -n “Checking year $year…”

# Now here is the rub.   The ‘cal’ program outputs
# a calendar (like the ones above)
# So we ask ‘cal’ to show us the calendar for
# Febuary (that’s the “02″) of the “$year”
#
# and we grab the last line (tail -2)
# actually we are grabbing the last 2 lines
# but the last line is blank
#
# Anyway, if that “last line” is equal to “29″
# then we know that the 29th day was a Sunday.
#
# Follow that?
IS5SUNDAY=`cal 02 $year | tail -2`

# if it is a Sunday, then
if [ "$IS5SUNDAY" = "29" ]
then
# say YES to STDOUT
echo “yes”

# and add the year to out output file
echo “$year” >> leapyear.txt
else

# if it is not a Sunday, say NO to STDOUT
echo “no”
fi

# OK, now we increment the year counter by 4
year=`expr $year + 4`

# Note that we are ASSUMING that leap years happen every 4 years
# or not at all.  This is not true for years that end in 1900
# (see above discussion on division by 100 and 400) but
# in reality it causes no harm, because although the
# script will test to see if the 29th of February was
# a Sunday, the answer will be NO, however, the reason for this
# answer will be because there was no 29th of February.
#
# So we get the “right” answer (no the 29th of Feb was not Sunday)
# for the “wrong reason” (because there was no 29th of Feb)

done

The answer? These are the 5-Sunday-Februarys since the year 1000 a.d.: 1008, 1036, 1064, 1092, 1120, 1148, 1176, 1204, 1232, 1260, 1288, 1316, 1344, 1372, 1400, 1428, 1456, 1484, 1512, 1540, 1568, 1596, 1624, 1652, 1680, 1708, 1736, 1756, 1784, 1824, 1852, 1880, 1920, 1948, 1976, 2004, 2032, 2060, 2088, 2128, 2156. (I stopped at 2156 because by then I will be dead and will presumably cease to care.)

So a 5-Sunday-February has occured only 36 times in the past 1,000 years. (It would be interesting to see if anything significant has happened on those days, any sort of trend that we might find. It was also be interesting to know what the proper plural of “February” is. Is it “Februarys” or “Februaries”?)

In looking for information about this, I came across a very interesting document: Frequently Asked Questions about Calendars, which is much more interesting (or was to me) than it’s name might imply. It also reminded me of one of the things I really enjoy about the web — being able to research something from the comfort of my own living room and coming across well-compiled, well-displayed information. (It was nice to read something different than my usual crowd of technology and other news, web design, etc.)

Among other things, it will explain why the calendar for September, 1752 looks to strange.

 cal 09 1752
   September 1752
Su Mo Tu We Th Fr Sa
       1  2 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

And if you think that’s bad, then read the Calendar FAQ and notice that in a few places, December 25th (Christmas) came the day after December 14th! Boy, I bet there were a lot of husbands who were stuck trying to explain to their wives why they didn’t have a Christmas present for them. (“But I thought I had another 10 days to shop!!!”)