I have a strange requirement where I need a find the date based on given number and type = before/after parameter
i.e., for example
Date = new Date() - 3/8/2020 (It can be any date)
type = before
days = 7(It can be any number)
Now I need to find the date excluding the weekends.
In this case it would be 23/7/2020 .Because 2/8,1/8,26/7,25/7 are weekends, so those should be excluded and calculated.
Simillarly if type = after , date will be 12/8/2020 .In this case 8/8 and 9/8 are weekends and those will be excluded.
So how can we implement this as function that takes date,days,type as parameters and return the date.
i.e.,
function calculateDate(day,days,type){
/* Some logic
if(new Date(day).getDay() !== 6||7){};
*/
return date
}
Note : I cant use any libraries like moment/dayjs etc as I have restrictions with the development tool Im using..I need to implement in pure javascript logic
Can any javascript datetime expert help me on this as I couldn't crack this.
Thanks in advance