From 59e55e40b222cf06454f0bb936d26a9936a37913 Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Thu, 2 Feb 2012 13:51:11 +0000 Subject: Fixed #8315 - take leap years into account in focusNext/PreviousYear svn changeset:22857/svn branch:6.7 --- .../vaadin/terminal/gwt/client/ui/VCalendarPanel.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/com') diff --git a/src/com/vaadin/terminal/gwt/client/ui/VCalendarPanel.java b/src/com/vaadin/terminal/gwt/client/ui/VCalendarPanel.java index 0f45e7185b..96ca818bb4 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VCalendarPanel.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VCalendarPanel.java @@ -626,8 +626,15 @@ public class VCalendarPanel extends FocusableFlexTable implements * Selects the previous year */ private void focusPreviousYear(int years) { + int currentMonth = focusedDate.getMonth(); focusedDate.setYear(focusedDate.getYear() - years); - displayedMonth.setYear(displayedMonth.getYear() - years); + /* + * If the focused date was a leap day (Feb 29), the new date becomes Mar + * 1 if the new year is not also a leap year. Set it to Feb 28 instead. + */ + if (focusedDate.getMonth() != currentMonth) { + focusedDate.setDate(0); + } renderCalendar(); } @@ -635,8 +642,16 @@ public class VCalendarPanel extends FocusableFlexTable implements * Selects the next year */ private void focusNextYear(int years) { + int currentMonth = focusedDate.getMonth(); focusedDate.setYear(focusedDate.getYear() + years); displayedMonth.setYear(displayedMonth.getYear() + years); + /* + * If the focused date was a leap day (Feb 29), the new date becomes Mar + * 1 if the new year is not also a leap year. Set it to Feb 28 instead. + */ + if (focusedDate.getMonth() != currentMonth) { + focusedDate.setDate(0); + } renderCalendar(); } -- cgit v1.2.3