showingDate.setYear(showingDate.getYear() + 1);\r
updateCalendar();\r
} else if (sender == prevMonth) {\r
- showingDate.setMonth(showingDate.getMonth() - 1);\r
+ int currentMonth = showingDate.getMonth();\r
+ showingDate.setMonth(currentMonth - 1);\r
+\r
+ /*\r
+ * If the selected date was e.g. 31.12 the new date would be\r
+ * 31.11 but this date is invalid so the new date will be 1.12.\r
+ * This is taken care of by decreasing the date until we have\r
+ * the correct month.\r
+ */\r
+ while (showingDate.getMonth() == currentMonth) {\r
+ showingDate.setDate(showingDate.getDate() - 1);\r
+ }\r
+\r
updateCalendar();\r
} else if (sender == nextMonth) {\r
- showingDate.setMonth(showingDate.getMonth() + 1);\r
+ int currentMonth = showingDate.getMonth();\r
+ showingDate.setMonth(currentMonth + 1);\r
+ int requestedMonth = (currentMonth + 1) % 12;\r
+\r
+ /*\r
+ * If the selected date was e.g. 31.3 the new date would be 31.4\r
+ * but this date is invalid so the new date will be 1.5. This is\r
+ * taken care of by decreasing the date until we have the\r
+ * correct month.\r
+ */\r
+ while (showingDate.getMonth() != requestedMonth) {\r
+ showingDate.setDate(showingDate.getDate() - 1);\r
+ }\r
+\r
updateCalendar();\r
}\r
} else {\r