]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix for #2202 - DateField skips a month
authorArtur Signell <artur.signell@itmill.com>
Mon, 1 Dec 2008 19:34:53 +0000 (19:34 +0000)
committerArtur Signell <artur.signell@itmill.com>
Mon, 1 Dec 2008 19:34:53 +0000 (19:34 +0000)
svn changeset:6056/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ui/ICalendarPanel.java

index 1dc64187f6d43e6d723e3131f762da8b573e96ac..6f386e231afed111702a09db67219a6a80e2546b 100644 (file)
@@ -274,10 +274,35 @@ public class ICalendarPanel extends FlexTable implements MouseListener {
                 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