The monthshift function (starting on march 1st): Torsten Sillke, 1999-03-15 The step function: s(month) 8 + x x x x x x x x x x x x | | 7 + x x x x x x x x x x x o_A | | 6 + x x x x x x x x x x_D o o | | 5 + x x x x x x x x o o o o | | 4 + x x x x x x o o o o o o | | 3 + x x x x x_B o o o o o o o | | 2 + x x x o o o o o o o o o | | 1 + x o_C o o o o o o o o o o | | 0 +----o----+----+----+----+----+----+----+----+----+----+----+-> month 0 1 2 3 4 5 6 7 8 9 10 11 12 mar apr may jun jul aug sep oct nov dec jan feb 0 1 1 2 2 3 4 4 5 5 6 7 s(month) 0 31 61 92 122 153 184 214 245 275 306 337 monthshift s(month) = monthshift - 30*(month-1) We are looking for lines that separate the 'o' from the 'x'. So, which lines are above A and C but below B and D? Let s = floor( a * month + b ) Constraints: (A) 12 a + b >= 7 (B) 5 a + b < 3 (C) 2 a + b >= 1 (D) 10 a + b < 6 The admissable parameter (a,b) are inside the quadrangle ( 4/7, 1/7) line AB ( 3/5, 0 ) line BD ( 5/8, -1/4) line CD ( 3/5, -2/5) line AC The two edges on the right are excluded the left ones are included. For b = 0 we get the section 7/12 <= a < 3/5. Now we can select a nice fraction. Zeller's choise: a = 3/5, b = -2/5. I prefere: a = 19/32, b = 0 as the division is faster on a binary computer. Reference: - Chr. Zeller, Kalender-Formeln, Acta Mathematica, 9 (1887) 131-136 - A. D. Bradley, The Day of the Week for Gregorian Calendars ?? 82-87 - Keith & Craver; The ultimate perpetual calendar?, JoRM 22:4 (1990) 280-282 day of the week as a 44 character expression in C. (illegal use of --) The following 45 character C expression by Keith is correct. dow(y,m,d) { return (d+=m<3?y--:y-2,23*m/9+d+4+y/4-y/100+y/400)%7; } - A. W. Butkewitsch, M. S. Selikson - Ewige Kalender, Teubner (Leipzig) 1974 Kleine Naturwissenschaftliche Bibliothek, Bd. 23, p98-113 ISBN 3-322-00393-0 - Heinz Bachmann, Kalenderarithmetik, 2nd Ed., Juris Verlag, Z"urich, 1984, ISBN 3-260-05035-0, p26-42