Well, you can simply say that this is correct ... Assuming the t[] array is correct, which you can only check with 12 spot checks (one for each month using any day / year).
y -= m < 3 is a good trick. He creates a “virtual year,” which begins on March 1 and ends on February 28 (or 29), adding an extra day (if any) at the end of the year; or, rather, at the end of last year. So, for example, virtual 2011 began on March 1 and ends on February 29, and virtual year 2012 begins on March 1 and ends next February 28.
By putting the added day on leap years at the end of the virtual year, the rest of the expression will be greatly simplified.
Let's look at the amount:
(y + y/4 - y/100 + y/400 + t[m-1] + d) % 7
In a normal year, 365 days. This is 52 weeks plus 1 day. Thus, the day of the week shifts one day per year, in general. This is what the term y does; he adds one per day for each year.
But every four years is a leap year. They contribute an extra day every four years. Thanks to the use of virtual years, we can simply add y/4 to the amount to calculate how many leap days will happen during y years. (Note that this formula assumes that integer division is rounded down.)
But this is not entirely correct, because every 100 years is not a leap year. Therefore, we need to subtract y/100 .
Except that every 400 years again a leap year. Therefore, we must add y/400 .
Finally, we simply add the day of the month d and the offset from the table, which depends on the month (since the boundaries of the month throughout the year are pretty arbitrary).
Then take the whole thing mod 7, as this is how long a week goes by.
(If the weeks were eight days, for example, what would have changed in this formula? Well, it would obviously be the 8th. Also y should be 5*y , because 365% 8 == 5. Now the table of the month t[] needs to be configured. This is it.)
By the way, the Wikipedia expression that the calendar is “good until 9999” is completely arbitrary. This formula is good because we adhere to the Gregorian calendar for a long time, be it 10 years, 100 years, 1000 years or 1 million years.
[edit]
The above argument is essentially proof of induction. That is, assuming that the formula works for a specific (y, m, d), you prove that it works for (y + 1, m, d) and (y, m, d + 1). (Where y is the "virtual year", starting March 1.) So, the main question: does the amount change by the correct amount when moving from one year to another? With knowledge of the rules of a leap year, and with a “virtual year” having an extra day at the end of the year, this is trivial.