README revision 1.1
11.1ScgdThe cal(1) date routines were written from scratch, basically from first 21.1Scgdprinciples. The algorithm for calculating the day of week from any 31.1ScgdGregorian date was "reverse engineered". This was necessary as most of 41.1Scgdthe documented algorithms have to do with date calculations for other 51.1Scgdcalendars (e.g. julian) and are only accurate when converted to gregorian 61.1Scgdwithin a narrow range of dates. 71.1Scgd 81.1Scgd1 Jan 1 is a Saturday because that's what cal says and I couldn't change 91.1Scgdthat even if I was dumb enough to try. From this we can easily calculate 101.1Scgdthe day of week for any date. The algorithm for a zero based day of week: 111.1Scgd 121.1Scgd calculate the number of days in all prior years (year-1)*365 131.1Scgd add the number of leap years (days?) since year 1 141.1Scgd (not including this year as that is covered later) 151.1Scgd add the day number within the year 161.1Scgd this compensates for the non-inclusive leap year 171.1Scgd calculation 181.1Scgd if the day in question occurs before the gregorian reformation 191.1Scgd (3 sep 1752 for our purposes), then simply return 201.1Scgd (value so far - 1 + SATURDAY's value of 6) modulo 7. 211.1Scgd if the day in question occurs during the reformation (3 sep 1752 221.1Scgd to 13 sep 1752 inclusive) return THURSDAY. This is my 231.1Scgd idea of what happened then. It does not matter much as 241.1Scgd this program never tries to find day of week for any day 251.1Scgd that is not the first of a month. 261.1Scgd otherwise, after the reformation, use the same formula as the 271.1Scgd days before with the additional step of subtracting the 281.1Scgd number of days (11) that were adjusted out of the calendar 291.1Scgd just before taking the modulo. 301.1Scgd 311.1ScgdIt must be noted that the number of leap years calculation is sensitive 321.1Scgdto the date for which the leap year is being calculated. A year that occurs 331.1Scgdbefore the reformation is determined to be a leap year if its modulo of 341.1Scgd4 equals zero. But after the reformation, a year is only a leap year if 351.1Scgdits modulo of 4 equals zero and its modulo of 100 does not. Of course, 361.1Scgdthere is an exception for these century years. If the modulo of 400 equals 371.1Scgdzero, then the year is a leap year anyway. This is, in fact, what the 381.1Scgdgregorian reformation was all about (a bit of error in the old algorithm 391.1Scgdthat caused the calendar to be inaccurate.) 401.1Scgd 411.1ScgdOnce we have the day in year for the first of the month in question, the 421.1Scgdrest is trivial. 43