Leap days are a civil-date rule, not a special layout exception.
In the Gregorian calendar, a year is leap when it is divisible by 4, except century years unless they are also divisible by 400. That makes 1900 a common year and 2000 a leap year. February 2000 has 29 dates, so the leap rule must run before weekday offsets and row counts are calculated.
The 400-year cycle gives a useful regression invariant: 400 Gregorian years contain 146,097 days, exactly 20,871 weeks. Weekday/date patterns therefore repeat across the full cycle. A single leap-year check cannot prove the full cycle; century boundaries matter.
For a calendar engine, test the edges explicitly: 1899–1901 and 1999–2001. Confirm February’s date count, the weekday of March 1, and that each day appears once in the grid. Keep leap-year logic separate from weekday arithmetic and cell placement so a failed assertion points to the right layer.
February 2000 example: https://www.betacalendars.com/february-calendar.html
Calendar project: https://www.betacalendars.com/
Leap days are a civil-date rule, not a special layout exception.
In the Gregorian calendar, a year is leap when it is divisible by 4, except century years unless they are also divisible by 400. That makes 1900 a common year and 2000 a leap year. February 2000 has 29 dates, so the leap rule must run before weekday offsets and row counts are calculated.
The 400-year cycle gives a useful regression invariant: 400 Gregorian years contain 146,097 days, exactly 20,871 weeks. Weekday/date patterns therefore repeat across the full cycle. A single leap-year check cannot prove the full cycle; century boundaries matter.
For a calendar engine, test the edges explicitly: 1899–1901 and 1999–2001. Confirm February’s date count, the weekday of March 1, and that each day appears once in the grid. Keep leap-year logic separate from weekday arithmetic and cell placement so a failed assertion points to the right layer.
February 2000 example: https://www.betacalendars.com/february-calendar.html
Calendar project: https://www.betacalendars.com/