react-native-calendars
react-native-calendars copied to clipboard
"showSixWeeks" show 5 weeks or 7 weeks when firstDay != 0
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:
-
npm ls react-native-calendars
: [email protected] -
npm ls react-native
: [email protected]
Came here to report the same issue
7 weeks:
5 weeks:
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);
}