if (timeRangeUnit === TimeRangeUnit.MONTH) {
const list = [];
const daysInMonth = dayjs(`${year}-${month}-01`).daysInMonth();
for (let i = 1; i <= daysInMonth; i++) {
const date = dayjs(`${year}-${month}-${i.toString().padStart(2, '0')}`);
const formattedDate = date.format('YYYY-MM-DD');
const items = sortedScheduleListAndConsultationListAndBreakTime.filter((item) => dayjs(item.startedAt).isSame(date, 'day'));
list.push({ date: new Date(formattedDate), items });
}
list?.reduce(
(acc, cur) => {
acc.consultationCount += cur.items?.filter((item) => item?.ptMemberProfile && item?.trainerProfile).length;
acc.ptScheduleCount += cur.items?.filter((item) => item?.ptToken).length;
return acc;
},
{ consultationCount: 0, ptScheduleCount: 0 }
);
return list.sort((a, b) => a.date.getTime() - b.date.getTime());
} else if (timeRangeUnit === TimeRangeUnit.WEEK) {
const list = [];
const currentWeekStart = dayjs(`${year}-${month}-${day}`).startOf('week').day(0).toDate();
const currentWeekEnd = dayjs(currentWeekStart).add(7, 'day').toDate();
for (let i = 0; i < 7; i++) {
const date = dayjs(currentWeekStart).add(i, 'day').toDate();
const items = sortedScheduleListAndConsultationListAndBreakTime.filter(
(item) => dayjs(item.startedAt).isSame(date, 'day') && dayjs(item.startedAt).isAfter(currentWeekStart, 'day') && dayjs(item.startedAt).isBefore(dayjs(currentWeekEnd).add(1, 'day'), 'day')
);
list.push({ date, items });
}
list?.reduce(
(acc, cur) => {
acc.consultationCount += cur.items.filter((item) => item?.ptMemberProfile && item?.trainerProfile).length;
acc.ptScheduleCount += cur.items.filter((item) => item?.ptToken).length;
return acc;
},
{ consultationCount: 0, ptScheduleCount: 0 }
);
return list.sort((a, b) => a.date.getTime() - b.date.getTime());
}