diff options
author | Ahmed Ashour <asashour@yahoo.com> | 2017-10-16 17:21:23 +0200 |
---|---|---|
committer | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-10-16 18:21:23 +0300 |
commit | 4148d910a556c873477da62f1e31b0e285b8b4d9 (patch) | |
tree | 7caad300ff6431d64ca7b3ebd53ba996967013a1 /client | |
parent | 9b4bc1073527214437d41681741ce05f5fc60c56 (diff) | |
download | vaadin-framework-4148d910a556c873477da62f1e31b0e285b8b4d9.tar.gz vaadin-framework-4148d910a556c873477da62f1e31b0e285b8b4d9.zip |
Fix AbstractDateField to correctly show week day names (#10188)
Fixes #9200
Diffstat (limited to 'client')
-rw-r--r-- | client/src/main/java/com/vaadin/client/DateTimeService.java | 33 | ||||
-rw-r--r-- | client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java | 5 |
2 files changed, 30 insertions, 8 deletions
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<R extends Enum<R>> // 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, "<strong>" + getDateTimeService().getShortDay(day) + "</strong>"); |