Repository: primefaces/primefaces (java)

Issue:
DatePicker: firstDayWeekOffset not calculated / IndexOfOutBound while submitting
It was introduced here: #5713


i have the problem when i enable week selection (like in the showcase) and set firstDayOfWeek=2, that firstDayWeekOffset is not caulcated. SundayIndex will become 5:

```
            var sundayIndex = this.getSundayIndex();
            if (this.options.locale.firstDayWeekOffset === undefined) {
                if (sundayIndex == 0) {
                    this.options.locale.firstDayWeekOffset = 6;
                }
                else if (sundayIndex == 1) {
                    this.options.locale.firstDayWeekOffset = 12;
                }
                else if (sundayIndex == 6) {
                    this.options.locale.firstDayWeekOffset = 4;
                }
                else {
                    this.options.showWeek = false;
                }
            }
```

@fanste i dont understand everything at all. Do you have a idea?

Pull request:
Fixes #13608 15.0.3 firstDayWeekOffset not calculated / IndexOfOutBound while submitting
Fixes #13608 15.0.3 firstDayWeekOffset not calculated / IndexOfOutBound while submitting

Patch:
diff --git a/primefaces/src/main/java/org/primefaces/util/CalendarUtils.java b/primefaces/src/main/java/org/primefaces/util/CalendarUtils.java
index 2162b226ab..6340f580b9 100644
--- a/primefaces/src/main/java/org/primefaces/util/CalendarUtils.java
+++ b/primefaces/src/main/java/org/primefaces/util/CalendarUtils.java
@@ -648,17 +648,22 @@ public class CalendarUtils {
         }
 
         // fast return
-        if (!input.contains(token)) {
+        if (input == null || !input.contains(token)) {
             return Collections.emptyList();
         }
 
         int tokenIndex = input.indexOf(token);
         String from = input.substring(0, tokenIndex);
         String to = input.substring(tokenIndex + token.length());
+
         if (week) {
             // hardcoded pattern, see JS:
             // formattedValue += ' (' + this.options.locale.weekHeader + ' ' + week + ')';
-            to = to.substring(0, to.lastIndexOf(" ("));
+            int weekNumberIndex = to.lastIndexOf(" (");
+            // there are cases when weeknumber might not get displayed on client and therefore not submitted
+            if (weekNumberIndex != -1) {
+                to = to.substring(0, weekNumberIndex);
+            }
         }
 
         return Arrays.asList(from, to);
diff --git a/primefaces/src/main/resources/META-INF/resources/primefaces/datepicker/0-datepicker.js b/primefaces/src/main/resources/META-INF/resources/primefaces/datepicker/0-datepicker.js
index 05475568dd..2c75f60e77 100644
--- a/primefaces/src/main/resources/META-INF/resources/primefaces/datepicker/0-datepicker.js
+++ b/primefaces/src/main/resources/META-INF/resources/primefaces/datepicker/0-datepicker.js
@@ -685,7 +685,7 @@
                                 formattedValue += ' ' + this.options.rangeSeparator + ' ' + this.formatDateTime(endDate);
                             }
 
-                            if (this.options.view === 'week') {
+                            if (this.options.view === 'week' && this.options.showWeek) {
                                 var startDateMeta = { day: startDate.getDate(), month: startDate.getMonth(), year: startDate.getFullYear() };
                                 var week = this.options.weekCalculator(startDateMeta);
                                 formattedValue += ' (' + this.options.locale.weekHeader + ' ' + week + ')';


Test patch:
diff --git a/primefaces/src/test/java/org/primefaces/util/CalendarUtilsTest.java b/primefaces/src/test/java/org/primefaces/util/CalendarUtilsTest.java
index cff2f05e74..743c6bd24e 100644
--- a/primefaces/src/test/java/org/primefaces/util/CalendarUtilsTest.java
+++ b/primefaces/src/test/java/org/primefaces/util/CalendarUtilsTest.java
@@ -221,8 +221,10 @@ class CalendarUtilsTest {
         assertEquals(2, splitRange.size());
         assertEquals("2021-03-01", splitRange.get(0));
         assertEquals("2021-03-31", splitRange.get(1));
+
         splitRange = CalendarUtils.splitRange("2021-03-01", "yyyy-MM-dd", "-", false);
         assertTrue(splitRange.isEmpty());
+
         splitRange = CalendarUtils.splitRange("", "yyyy-MM-dd", "-", false);
         assertTrue(splitRange.isEmpty());
 
@@ -237,13 +239,26 @@ class CalendarUtilsTest {
         assertEquals(2, splitRange.size());
         assertEquals("2021-03-01", splitRange.get(0));
         assertEquals("2021-03-31", splitRange.get(1));
+
         splitRange = CalendarUtils.splitRange("2021-03-01 (Wk 21)", "yyyy-MM-dd", "-", true);
         assertTrue(splitRange.isEmpty());
+
         splitRange = CalendarUtils.splitRange("", "yyyy-MM-dd (Wk 21)", "-", true);
         assertTrue(splitRange.isEmpty());
 
+        splitRange = CalendarUtils.splitRange("2021-03-01 - 2021-03-31 (Wk NaN)", "yyyy-MM-dd", "-", true);
+        assertEquals(2, splitRange.size());
+        assertEquals("2021-03-01", splitRange.get(0));
+        assertEquals("2021-03-31", splitRange.get(1));
+
+        splitRange = CalendarUtils.splitRange("2021-03-01 - 2021-03-31", "yyyy-MM-dd", "-", true);
+        assertEquals(2, splitRange.size());
+        assertEquals("2021-03-01", splitRange.get(0));
+        assertEquals("2021-03-31", splitRange.get(1));
+
         assertThrows(FacesException.class, () -> {
             CalendarUtils.splitRange("2021 - 03 - 01 - 2021 - 03 - 31 (Wk 21)", "yyyy - MM - dd", "-", true);
         });
     }
+
 }