What may be of interest is the method. The fundamental data structure is a list containing one element for each year since the year 1, with an extra 0 at the beginning to allow use of 1-based indexing. Each element in this list is itself a list of the number of days for each month of that particular year. We calculate this once, when the first Date object is instantiated. (Unless a date beyond 2050 is desired, then the list is extended as far as needed). We also cache the total number of days for each year in another list, to reduce calculation.
Using these two lists, it is trivial to calculate for any date the number of days since Jan 1 of the year 1 (a Saturday), and then, the day of the week is a simple mod 7 operation.
Here is output from the Unix cal function:
The month of September in the year 1752 was special (in Great Britain and the United States, at least). It is the month from which extra days were dropped in order to bring the calendar back into register with the earth's actual position, before changing from the Julian to the Gregorian calendar. (In Catholic Europe the change was made in October 1582, and only ten days were dropped, from 5 October 1582 to 14 October 1582).
We deal with this simply by making L[1752][9] = 19.
Here is a test function that exercises the class:
And the output:
14,609 days since the first moonwalk. I watched on TV!
I do hope our descendants are still here in 2637. Update: there seems to be a bug, either in my code or the cal function. It shows July 19, 2637 as a Wed. All the other dates check out. Ideas?
The entire listing: