if (emptyGrid) {
ranges.push({ start: new Date(IndividualBugetFigures.awardYears_Unformatted[elementIndex].Begin), end: new Date(IndividualBugetFigures.awardYears_Unformatted[elementIndex].End) })
}
else {
for (var i = 1; i < thisGridData.length; i++) {
//debugger;
if (i === 1 && new Date(thisGridData[i].childEffBegDate) > new Date(IndividualBugetFigures.awardYears_Unformatted[elementIndex].Begin)) {
ranges.push({ start: new Date(IndividualBugetFigures.awardYears_Unformatted[elementIndex].Begin), end: new Date(moment(thisGridData[i].childEffBegDate).subtract(1, 'days').calendar()) });
}
else {
if (i + 1 < thisGridData.length) {
//console.log('beginDate EndDate', new Date(thisGridData[i].childEffEndDate) + ' ' + new Date(thisGridData[i + 1].childEffBegDate));
console.log('in the and part', new Date(moment(thisGridData[i].childEffEndDate).add(1, 'days').calendar()) + ' ' + new Date(thisGridData[i + 1].childEffBegDate));
//debugger;
if (new Date(moment(thisGridData[i].childEffEndDate).add(1, 'days').calendar()) === new Date(thisGridData[i + 1].childEffBegDate)) {
if (i + 1 === thisGridData.length -1) {
return false;
}
}
else if (new Date(thisGridData[i].childEffEndDate) < new Date(thisGridData[i + 1].childEffBegDate) && new Date(moment(thisGridData[i].childEffEndDate).add(1, 'days').calendar()) !== new Date(thisGridData[i + 1].childEffBegDate))
ranges.push({ start: new Date(moment(thisGridData[i].childEffEndDate).add(1, 'days').calendar()), end: new Date(moment(thisGridData[i + 1].childEffBegDate).subtract(1, 'days').calendar()) });
}
if (i === thisGridData.length - 1 && new Date(thisGridData[i].childEffEndDate) < new Date(IndividualBugetFigures.awardYears_Unformatted[elementIndex].End))
ranges.push({ start: new Date(moment(thisGridData[i].childEffEndDate).add(1, 'days').calendar()), end: new Date(IndividualBugetFigures.awardYears_Unformatted[elementIndex].End) });
}
}
}
The above code goes through the if statements as it should except when it gets to this part:
if (new Date(moment(thisGridData[i].childEffEndDate).add(1, 'days').calendar()) === new Date(thisGridData[i + 1].childEffBegDate)) {
if (i + 1 === thisGridData.length -1) {
return false;
}
}
When I console out:
console.log('in the and part', new Date(moment(thisGridData[i].childEffEndDate).add(1, 'days').calendar()) + ' ' + new Date(thisGridData[i + 1].childEffBegDate));
I get --
in the and part Fri Jan 02 2015 00:00:00 GMT-0600 (Central Standard Time) Fri Jan 02 2015 00:00:00 GMT-0600 (Central Standard Time)
So why doesn't the if statement evaluate to true? When I step through the code it gets to this line and then steps to next else if. Thanks in advance for the helpful comments.