diff options
author | Sauli Tähkäpää <sauli@vaadin.com> | 2014-10-04 00:03:38 +0300 |
---|---|---|
committer | Anna Koskinen <anna@vaadin.com> | 2014-11-03 13:16:47 +0200 |
commit | eb94e2a9be2d8ce34620fdedc90425e05785cdd8 (patch) | |
tree | f2c7714b1d541c7b490b83754f7be9c124bf18ee /server | |
parent | dda24122a7a0a0491fc5cac69792fe37a826803e (diff) | |
download | vaadin-framework-eb94e2a9be2d8ce34620fdedc90425e05785cdd8.tar.gz vaadin-framework-eb94e2a9be2d8ce34620fdedc90425e05785cdd8.zip |
Fix VCalendar to use correct year of week. (#14783)
Change-Id: Id55ad5ed620bd5c187b70ae2a2d0a4c4adea382a
Diffstat (limited to 'server')
-rw-r--r-- | server/src/com/vaadin/ui/Calendar.java | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/server/src/com/vaadin/ui/Calendar.java b/server/src/com/vaadin/ui/Calendar.java index 63ac9fe35c..72ff6eb0e0 100644 --- a/server/src/com/vaadin/ui/Calendar.java +++ b/server/src/com/vaadin/ui/Calendar.java @@ -516,7 +516,8 @@ public class Calendar extends AbstractComponent implements day.date = df_date.format(date); day.localizedDateFormat = weeklyCaptionFormatter.format(date); day.dayOfWeek = getDowByLocale(currentCalendar); - day.week = currentCalendar.get(java.util.Calendar.WEEK_OF_YEAR); + day.week = getWeek(currentCalendar); + day.yearOfWeek = getYearOfWeek(currentCalendar); days.add(day); @@ -560,6 +561,23 @@ public class Calendar extends AbstractComponent implements state.actions = createActionsList(actionMap); } + private int getWeek(java.util.Calendar calendar) { + return calendar.get(java.util.Calendar.WEEK_OF_YEAR); + } + + private int getYearOfWeek(java.util.Calendar calendar) { + // Would use calendar.getWeekYear() but it's only available since 1.7. + int week = getWeek(calendar); + int month = calendar.get(java.util.Calendar.MONTH); + int year = calendar.get(java.util.Calendar.YEAR); + + if (week == 1 && month == java.util.Calendar.DECEMBER) { + return year + 1; + } + + return year; + } + private void setActionsForEachHalfHour( Map<CalendarDateRange, Set<Action>> actionMap, Date start, Date end, Action.Handler actionHandler) { @@ -1772,7 +1790,7 @@ public class Calendar extends AbstractComponent implements String[] splitted = event.split("w"); if (splitted.length == 2) { try { - int yr = 1900 + Integer.parseInt(splitted[0]); + int yr = Integer.parseInt(splitted[0]); int week = Integer.parseInt(splitted[1]); fireWeekClick(week, yr); } catch (NumberFormatException e) { |