correctly calculate the days in last month when building calendar