Utilizing the MultipleDatePicker plugin to enable selection of multiple dates within a year. I have incorporated a checkbox feature that, when checked, will automatically mark all Sundays in the calendar.
However, an issue arises when unchecking the checkbox. It fails to deselect all previously selected Sundays in the calendar. To troubleshoot this problem, I implemented the following code snippet utilizing getTime()
:
var selected = $scope.selectedDates;
for (var i = 0; i < $scope.selectedDates.length; i++) {
var date1 = new Date(selected[i]).getTime();
console.log('date1[' + i + '] = ' + date1 + ' ' + moment($scope.selectedDates[i], 'MM-DD-YYYY'));
for (var j = 0; j < sundays.length; j++) {
var date2 = new Date(sundays[j]).getTime();
console.log('date2[' + j + '] = ' + date2 + ' ' + moment(sundays[j], 'MM-DD-YYYY'));
if (date1 === date2) {
selected.splice(i, 1);
break;
}
}
}
After reviewing the comparisons made between the dates, some appear to match while others do not. Can you identify the flaw in the code?
For further investigation and demonstration of the issue, access the Plunker link here.