From d9b114ab8e47a8b1735067bcc3b96f19f44382ca Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 1 Dec 2008 19:34:53 +0000 Subject: [PATCH] Fix for #2202 - DateField skips a month svn changeset:6056/svn branch:trunk --- .../gwt/client/ui/ICalendarPanel.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ICalendarPanel.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ICalendarPanel.java index 1dc64187f6..6f386e231a 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ICalendarPanel.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/ICalendarPanel.java @@ -274,10 +274,35 @@ public class ICalendarPanel extends FlexTable implements MouseListener { showingDate.setYear(showingDate.getYear() + 1); updateCalendar(); } else if (sender == prevMonth) { - showingDate.setMonth(showingDate.getMonth() - 1); + int currentMonth = showingDate.getMonth(); + showingDate.setMonth(currentMonth - 1); + + /* + * If the selected date was e.g. 31.12 the new date would be + * 31.11 but this date is invalid so the new date will be 1.12. + * This is taken care of by decreasing the date until we have + * the correct month. + */ + while (showingDate.getMonth() == currentMonth) { + showingDate.setDate(showingDate.getDate() - 1); + } + updateCalendar(); } else if (sender == nextMonth) { - showingDate.setMonth(showingDate.getMonth() + 1); + int currentMonth = showingDate.getMonth(); + showingDate.setMonth(currentMonth + 1); + int requestedMonth = (currentMonth + 1) % 12; + + /* + * If the selected date was e.g. 31.3 the new date would be 31.4 + * but this date is invalid so the new date will be 1.5. This is + * taken care of by decreasing the date until we have the + * correct month. + */ + while (showingDate.getMonth() != requestedMonth) { + showingDate.setDate(showingDate.getDate() - 1); + } + updateCalendar(); } } else { -- 2.39.5