farhoudshapouran/react-native-ui-datepicker

Noticing a disconnect when trying to highlight a calendar week

Opened this issue · 0 comments

Seeing an issue when trying to highlight 7 days starting on a Sunday. See the following image:
Screenshot 2024-10-06 at 7 26 24 PM

Issue is that the highlighting is breaking on 1/28/25. Seems to only happen on the last week of the month.

import DateTimePicker from "react-native-ui-datepicker";
import dayjs, { Dayjs } from "dayjs";

//newSelectedDate - the starting date
const [selectedDates, setSelectedDates] = useState<Dayjs[]>([]);

const handleHighlightWeek = (dates: Date[]) => {
    const selectedDate = dayjs(newSelectedDate).startOf("day");
    const startOfWeek = selectedDate.startOf("week");

    const weekDates: Dayjs[] = [];
    for (let i = 0; i < 7; i++) {
      weekDates.push(startOfWeek.add(i, "day"));
    }

    setSelectedDates(weekDates);
    
    <DateTimePicker
            mode="multiple"
            dates={selectedDates}
            onChange={handleHighlightWeek(params.dates)}
            minDate={today}
          />
        </View>
  };