i am trying to get all day between 2 timestamp and for specific day name.
i have a start1 is moment(first date) and end1 is moment(last date). And i have a list of day with id (day).
this.datesDailySelected = [];
var start1 = moment(new Date(this._data.row.plannedDispatch));
var end1 = moment(this.datesForm.controls["dailyExpiryDate"].value);
this.selectedItemsList.forEach((item) => {
var current = start1.clone();
var day;
switch (item.name) {
case "Sunday":
day = 0;
break;
case "Monday":
day = 1;
break;
case "Tuesday":
day = 2;
break;
case "Wednesday":
day = 3;
break;
case "Thursday":
day = 4;
break;
case "Friday":
day = 5;
break;
case "Saturday":
day = 6;
break;
}
while (current.day(7 + day).isBefore(end1)) {
this.datesDailySelected.push(current.clone().format("YYYY-MM-DD"));
}
console.log(this.datesDailySelected);
});
wherever i choose 2 date and a specific day name example (friday), i retreive all date without day in this week!
i thing i do something wrong with my code.
Real example:
start1 : "2021-12-20T07:50:00.000Z"
end1: "2021-12-25T07:50:00.000Z"
day choosed: friday with day = 5
output = empty list.
output must be ["2021-12-24"]