I need to create function that produces a date range based on when a user's meeting day is. The users meet on different days, in this example I will use "John" who meets with his group on Wednesdays. The two dates I need are the most recent Wednesday and the next Wednesday. For example if today is Monday Nov 15th the function should return 11/10/2021 & 11/17/2021
My current code only works on the meeting day or after it has already happened because it pulls this week's Wednesday and next week's Wednesday...
const DateRange = () => {
switch (user.groups[0].meetingDay) {
case "monday":
return [1, 8];
case "tuesday":
return [2, 9];
case "wednesday":
return [3, 10];
case "thursday":
return [4, 11];
case "friday":
return [5, 12];
case "saturday":
return [6, 13];
case "sunday":
return [0, 7];
}
};
const firstNumber = DateRange().push(0);
const secondNumber = DateRange().pop(0);
const goalsDateRangeStart = moment().day(firstNumber).format("l");
const goalsDateRangeEnd = moment().day(secondNumber).format("l");
When the code above is used on Nov 15th it will give me 11/17/2021-11/24/2021