wix / react-native-calendars

React Native Calendar Components 🗓️ 📆
MIT License
9.52k stars 2.95k forks source link

"showSixWeeks" show 5 weeks or 7 weeks when firstDay != 0 #2350

Open ng-ha opened 11 months ago

ng-ha commented 11 months ago

Description

With option "showSixWeeks" calendar shows 5 weeks or 7 weeks when firstDay != 0.

Expected Behavior

"showSixWeeks" should always show 6 weeks so calendar's height doesn't change.

Environment

Please run these commands in the project folder and fill in their results:

TobbeLundberg commented 11 months ago

Came here to report the same issue

7 weeks: image

5 weeks: image

ThomasGuenard commented 6 months ago

I was struggling with this issue too.

I created a pull request that solve this behavior

The first week calculation wasn't taking into account the first day of the week

Here is my patch:

index 34ac965..6918af8 100644
--- a/node_modules/react-native-calendars/src/dateutils.js
+++ b/node_modules/react-native-calendars/src/dateutils.js
@@ -101,7 +101,7 @@ export function page(date, firstDayOfWeek = 0, showSixWeeks = false) {
     const ldow = (fdow + 6) % 7;
     firstDayOfWeek = firstDayOfWeek || 0;
     const from = days[0].clone();
-    const daysBefore = from.getDay();
+    const daysBefore = (from.getDay() + 7 - fdow) % 7;
     if (from.getDay() !== fdow) {
         from.addDays(-(from.getDay() + 7 - fdow) % 7);
     }