@@ -34,8 +34,7 @@ public class Calendar {
3434 static protected final int DEFAULT_CALS_PER_ROW = 3 ;
3535 static protected final int CALENDARWIDTH = 20 ;
3636 static protected final int SPACESBETWEENCALS = 2 ;
37- static protected final String [] MONTHLIST = {"" , "January" , "February" , "March" , "April" , "May" , "June" , "July" , "August" , "September" , "October" ,
38- "November" , "December" };
37+ static protected final String [] MONTHLIST = {"" , "January" , "February" , "March" , "April" , "May" , "June" , "July" , "August" , "September" , "October" , "November" , "December" };
3938 static protected final int TODAYHIGHLIGHT_FG = Output .WHITE ;
4039 static protected final int TODAYHIGHLIGHT_BG = Output .BLUE ;
4140
@@ -96,10 +95,12 @@ public static int getDayOfWeek(int month, int day, int year) {
9695 * @return
9796 */
9897 public static boolean isLeapYear (int year ) {
99- if ((year % 4 == 0 ) && (year % 100 != 0 ))
98+ if ((year % 4 == 0 ) && (year % 100 != 0 )) {
10099 return true ;
101- if (year % 400 == 0 )
100+ } else if (year % 400 == 0 ) {
102101 return true ;
102+ }
103+
103104 return false ;
104105 }
105106
@@ -244,9 +245,9 @@ public static String[] getCalDays(int month, int year) {
244245 // Insert spaces until we get to first day of the month in the calendar
245246 returnString [row ] += " " .repeat (firstDayOfMon );
246247
247- // Initialize the length of the each row
248+ // Initialize the length of each row
248249 // I can't just use the length of returnString[row] because the ANSI colored characters take up more room and that won't be
249- // printed. Therefore I'll keep the length of the returnString in a separate variable
250+ // printed. Therefore, I'll keep the length of the returnString in a separate variable
250251 returnStringLen [row ] = returnString [row ].length ();
251252
252253 // Create the day strings. After 7 days start a new line.
@@ -277,6 +278,7 @@ public static String[] getCalDays(int month, int year) {
277278 if (((day + firstDayOfMon ) % 7 == 0 ) || (day == daysInMonth [month ])) {
278279 // Ensure that the array element is padded with space characters
279280 if (returnStringLen [row ] < CALENDARWIDTH ) {
281+ // Pad the return string for this row with spaces
280282 returnString [row ] += " " .repeat (CALENDARWIDTH - returnStringLen [row ] + 1 );
281283 }
282284
@@ -285,6 +287,12 @@ public static String[] getCalDays(int month, int year) {
285287 }
286288 }
287289
290+ // Ensure the 5th row (row=4) is padded.
291+ // Fixed bug where 2/28 ended on Sunday, and we didn't have anything in row=4
292+ if (returnStringLen [4 ] == 0 ) {
293+ returnString [4 ] = " " .repeat (CALENDARWIDTH + 1 );
294+ }
295+
288296 // Ensure last row / array element is CALENDARWIDTH characters. Pad with spaces.
289297 int lastElement = returnString .length - 1 ;
290298 if (returnString [lastElement ].length () < CALENDARWIDTH ) {
0 commit comments