Create a function which brings me the days of the week from Monday to Sunday :
weekLabel(current) {
const week = [];
const weekFormat = [];
current.setDate(((current.getDate() - current.getDay()) + 1));
for (let i = 0; i < 7; i++) {
week.push(new Date(current));
current.setDate(current.getDate() + 1);
}
week.forEach((w) => {
weekFormat.push(moment(w).format('DD/MM/YYYY'));
});
return weekFormat;
},
In which current is what the function is waiting for, in this case it passes a date... this works correctly but when I pass it a date of a Sunday it already returns the days of the other week. I know that the week starts from Sunday but I would like to know if I can put it to start from Monday
The problem is that getDay() will always return 0 on Sunday, a solution could be to include an If so that when it reaches Sunday, I take it as if it were the Seventh day of the week. You can do it in the following way:
}
I already tried it and it gave results. I hope it helps you