From 4148d910a556c873477da62f1e31b0e285b8b4d9 Mon Sep 17 00:00:00 2001 From: Ahmed Ashour Date: Mon, 16 Oct 2017 17:21:23 +0200 Subject: Fix AbstractDateField to correctly show week day names (#10188) Fixes #9200 --- .../java/com/vaadin/client/DateTimeService.java | 33 +++++++++++++++++++--- .../vaadin/client/ui/VAbstractCalendarPanel.java | 5 +--- 2 files changed, 30 insertions(+), 8 deletions(-) (limited to 'client') diff --git a/client/src/main/java/com/vaadin/client/DateTimeService.java b/client/src/main/java/com/vaadin/client/DateTimeService.java index c1f6d70815..7367d686b6 100644 --- a/client/src/main/java/com/vaadin/client/DateTimeService.java +++ b/client/src/main/java/com/vaadin/client/DateTimeService.java @@ -96,6 +96,13 @@ public class DateTimeService { } } + /** + * Returns the localized short name of the specified day. + * + * @param day + * the day, {@code 0} is {@code SUNDAY} + * @return the localized short name + */ public String getShortDay(int day) { try { return LocaleService.getShortDayNames(locale)[day]; @@ -105,6 +112,11 @@ public class DateTimeService { } } + /** + * Returns the first day of the week, according to the used Locale. + * + * @return the localized first day of the week, {@code 0} is {@code SUNDAY} + */ public int getFirstDayOfWeek() { try { return LocaleService.getFirstDayOfWeek(locale); @@ -114,6 +126,12 @@ public class DateTimeService { } } + /** + * Returns whether the locale has twelve hour, or twenty four hour clock. + * + * @return {@code true} if the locale has twelve hour clock, {@code false} + * for twenty four clock + */ public boolean isTwelveHourClock() { try { return LocaleService.isTwelveHourClock(locale); @@ -145,9 +163,16 @@ public class DateTimeService { } } - public int getStartWeekDay(Date date) { - final Date dateForFirstOfThisMonth = new Date(date.getYear(), - date.getMonth(), 1); + /** + * Returns the first day of week of the specified {@code month}. + * + * @param month + * the month, not {@code null} + * @return the first day of week, + */ + public int getStartWeekDay(Date month) { + final Date dateForFirstOfThisMonth = new Date(month.getYear(), + month.getMonth(), 1); int firstDay; try { firstDay = LocaleService.getFirstDayOfWeek(locale); @@ -158,7 +183,7 @@ public class DateTimeService { } int start = dateForFirstOfThisMonth.getDay() - firstDay; if (start < 0) { - start = 6; + start += 7; } return start; } diff --git a/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java b/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java index 7ac882f9e4..b250d1bb53 100644 --- a/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java +++ b/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java @@ -783,10 +783,7 @@ public abstract class VAbstractCalendarPanel> // Print weekday names final int firstDay = getDateTimeService().getFirstDayOfWeek(); for (int i = 0; i < 7; i++) { - int day = i + firstDay; - if (day > 6) { - day = 0; - } + int day = (i + firstDay) % 7; if (isBelowMonth(getResolution())) { days.setHTML(headerRow, firstWeekdayColumn + i, "" + getDateTimeService().getShortDay(day) + ""); -- cgit v1.2.3