react-native-calendars icon indicating copy to clipboard operation
react-native-calendars copied to clipboard

Feature: auto-populate days in between for period marking

Open asjustis opened this issue 2 years ago • 3 comments

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.

asjustis avatar Feb 25 '23 09:02 asjustis

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.

stale[bot] avatar Jun 11 '23 09:06 stale[bot]

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',
      },
    };
  }, {});

aisflat439 avatar Dec 20 '23 18:12 aisflat439

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.

stale[bot] avatar Apr 22 '24 09:04 stale[bot]