standard year of 1700

After I try to change the standard year many time, I still can't explain this problem.
If the year I enter is before 2000AD, the first line showing days sometimes has trouble about too early to change to next line, so some days are in the wrong places.
For example, 1800AD Feb.1st is Wednesday, then 4th isn't Saturday but Sunday. That is I said the  program changes line too early.

But, if I enter a year after 2000AD, the first line sometimes have other problem. Though ths interger "first_space" is "n", sometimes the first day show on the "n"th place, so the amount of spaces before 1st day just only "n-1"! The program also changes line too early, but in this case, the day in socend line and after second line exactly right.
For example, 2001AD Mar.1st is Wednesday, that's wrong; 4th is Sunday, that is exactly right.

I can't find any bug in my code(Maybe just because I am unable to find it, dosen't mean it isn't real), expect in the future I can find a way to explain it.