I create a schedule function, for this I need to insert the week data into the assembly.
So, I create an array that will contain weeks from start_date to end_date.
1st Push in the array: start_date = Announced date (if the announced date is Sunday, then it takes into account the date of the next Monday); end_date = date saturday
2nd to nth Push in the array: start_date = date on Monday; end_date = date on Saturday or the announced end date, if it is within a week
var start = new Date("09/30/2016");
var end = new Date("11/2/2016");
var count = 0;
var sDate;
var eDate;
var dateArr = [];
while(start <= end){
if (start.getDay() == 0){
count = 0;
}else {
if(count == 0){
sDate = start;
count = 1
}else {
count = 1;
}
if(start.getDay() == 6 || start == end){
count = 1
eDate = start;
}else {
count = 1;
}
if(sDate && eDate){
sDate = new Date(sDate)
eDate = new Date(eDate)
dateArr.push({'startDate': sDate, 'endDate': eDate});
sDate = undefined;
eDate = undefined;
}
}
var newDate = start.setDate(start.getDate() + 1);
start = new Date(newDate);
}
But the result of Im get is
[{
'startDate':Sat Oct 01 2016 00:00:00 GMT+0530 (IST),
'endDate':Sat Oct 01 2016 00:00:00 GMT+0530 (IST),
},
{
'startDate':Tue Oct 04 2016 00:00:00 GMT+0530 (IST),
'endDate':Sat Oct 08 2016 00:00:00 GMT+0530 (IST),
},
{
'startDate':Tue Oct 11 2016 00:00:00 GMT+0530 (IST),
'endDate':Sat Oct 15 2016 00:00:00 GMT+0530 (IST),
},
{
'startDate':Tue Oct 18 2016 00:00:00 GMT+0530 (IST),
'endDate':Sat Oct 22 2016 00:00:00 GMT+0530 (IST),
},
{
'startDate':Tue Oct 25 2016 00:00:00 GMT+0530 (IST),
'endDate':Sat Oct 29 2016 00:00:00 GMT+0530 (IST),
}]
Edit:
Expected Result:
[{
'startDate':Fri Sep 30 2016 00:00:00 GMT+0530 (IST),
'endDate':Sat Oct 01 2016 00:00:00 GMT+0530 (IST),
},
{
'startDate':Mon Oct 03 2016 00:00:00 GMT+0530 (IST),
'endDate':Sat Oct 08 2016 00:00:00 GMT+0530 (IST),
},
{
'startDate':Mon Oct 10 2016 00:00:00 GMT+0530 (IST),
'endDate':Sat Oct 15 2016 00:00:00 GMT+0530 (IST),
},
{
'startDate':Mon Oct 17 2016 00:00:00 GMT+0530 (IST),
'endDate':Sat Oct 22 2016 00:00:00 GMT+0530 (IST),
},
{
'startDate':Mon Oct 24 2016 00:00:00 GMT+0530 (IST),
'endDate':Sat Oct 29 2016 00:00:00 GMT+0530 (IST),
},
{
'startDate':Mon Oct 31 2016 00:00:00 GMT+0530 (IST)
'endDate':Wed Nov 02 2016 00:00:00 GMT+0530 (IST),
}]