react-native-calendars
react-native-calendars copied to clipboard
Feature: auto-populate days in between for period marking
Hi, so that's a feature request. Seems it would be very intuitive use to have the ability only to set startingDay
and endingDay
for markedDates
variable rather than generating each day manually ourselves.
Description
Currently, we need to populate all the days manually for markedDates, even all the dates in between, which seems counterintuitive.
Expected Behavior
It would be a great feature to auto-populate all the dates in between startingDay and endingDay with the same color.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I agree. I just ran into this and expected it to work as OP described.
If you happen to:
- have found this
- have
date-fns
installed
const generateDateList = (startDateStr, endDateStr) => {
const startDate = parseISO(startDateStr);
const endDate = parseISO(endDateStr);
const dates = [];
let currentDate = startDate;
while (isBefore(currentDate, endDate)) {
dates.push(format(currentDate, 'yyyy-MM-dd'));
currentDate = addDays(currentDate, 1);
}
dates.push(format(endDate, 'yyyy-MM-dd'));
return dates;
};
/* later */
const markedDates = dateList.reduce((acc, date) => {
return {
...acc,
[date]: {
color: '#fff',
textColor: '#000',
},
};
}, {});
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.