From 7aac1060bde1b3d3eecf296ac577ac1692e69742 Mon Sep 17 00:00:00 2001 From: "Ahmad K. Bawaneh" Date: Thu, 2 Nov 2023 12:12:45 +0300 Subject: [PATCH] fix #873 Calendar - set first day of week in accordance with DateTimeFormatInfo --- domino-ui/pom.xml | 6 ----- .../domino/ui/datepicker/CalendarMonth.java | 22 ++++++++++++++----- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/domino-ui/pom.xml b/domino-ui/pom.xml index 30bd62a82..655e1d89b 100644 --- a/domino-ui/pom.xml +++ b/domino-ui/pom.xml @@ -126,14 +126,8 @@ domino-ui.css - loaders/domino-ui-waitMe.css - - **/*.min.css - - - ${build.directory}/classes diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/datepicker/CalendarMonth.java b/domino-ui/src/main/java/org/dominokit/domino/ui/datepicker/CalendarMonth.java index 19ad92633..fcb9d8830 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/datepicker/CalendarMonth.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/datepicker/CalendarMonth.java @@ -76,6 +76,7 @@ private void setDate(Date date) { private void updateView() { this.root.clearElement(); + int firstDayOfTheWeek = this.calendar.getDateTimeFormatInfo().firstDayOfTheWeek(); Date tempDate = new Date(this.date.getYear(), this.date.getMonth(), 1); int monthFirstDay = tempDate.getDay() == 0 ? 7 : tempDate.getDay(); @@ -85,17 +86,26 @@ private void updateView() { .addCss(dui_month_days_header) .apply( daysHeader -> { - for (int i = 0; i < 7; i++) { - daysHeader.appendChild(WeekDayHeader.create(this.calendar, i)); + int index = firstDayOfTheWeek; + while (index != -1) { + daysHeader.appendChild(WeekDayHeader.create(this.calendar, index)); + index = index + 1; + if (index > 6) { + index = 0; + } + if (index == firstDayOfTheWeek) { + index = -1; + } } })); this.monthData = new MonthData(this.date); MonthData monthBefore = monthData.getMonthBefore(); MonthData monthAfter = monthData.getMonthAfter(); - int diff = monthFirstDay + 1; + int offset = Math.abs(monthFirstDay - firstDayOfTheWeek); + int diff = offset + 1; int[] currentDaysCounter = new int[] {0}; - int[] monthBeforeDaysCounter = new int[] {monthBefore.getDaysCount() - monthFirstDay + 1}; + int[] monthBeforeDaysCounter = new int[] {monthBefore.getDaysCount() - offset + 1}; int[] monthAfterDaysCounter = new int[] {1}; int[] index = new int[] {0}; @@ -107,7 +117,7 @@ private void updateView() { daysRow -> { for (int day = 0; day < 7; day++) { CalendarDay calendarDay; - if (index[0] < monthFirstDay) { + if (index[0] < offset) { calendarDay = CalendarDay.create( this.calendar, @@ -118,7 +128,7 @@ private void updateView() { day, false); monthBeforeDaysCounter[0] = monthBeforeDaysCounter[0] + 1; - } else if (index[0] >= monthFirstDay + } else if (index[0] >= offset && index[0] < (monthData.getDaysCount() + diff - 1)) { calendarDay = CalendarDay.create(