I wouldn't be surprised if it was just a for loop checking for all the years in a range, whether they start on the same day of week, and are/are not leap years :)
The calculations are actually really easy. Note that the length of a (regular) year is 1 mod 7, which means weekdays slip by 1 day each year, except for leap years. Over the 400-year Gregorian calendar cycle, there are 97 leap years, for a total of 497 days of slip... so adding 400 years to the current calendar year will always yield the same calendar.
More specifically, there are 14 possible calendars. The leap year cycle is 4 days (excluding the 100 year skips), and the weekday cycle is 7 days, so the leap year×weekday cycle is 28 years. So the starting weekdays are on a 28-year cycle, but you have to slip your resulting calculation by the number of centuries from the beginning of the 400-year cycle (i.e., integer division of year by 100). You'll reuse a leap year calendar in 28 years (40 years, if it crosses a round-hundred year), and you'll reuse a non-leap year calendar in 6 or 11 years (12 or 6 years, if it cross a round-hundred year).
The easiest way to code it is to just precompute the year % 400 table and report the results.
> The leap year cycle is 4 days (excluding the 100 year skips)
I think you mean “The leap year cycle is 4 days (excluding the 100 year skips, except every fourth 100 years when they don’t),” eg how 2000 was a leap year despite this individual rule.
(I know it’s accounted for elsewhere in the modulo logic, but you shouldn’t resist the impulse to point out just how crazy it all is!)