Struggling to determine the weekday of a particular date next year? Take for example Tuesday, April 19, 2016 as the given date. What we need to calculate is: TUESDAY, April 18, 2017. Consistency with weekdays is crucial in this scenario.
The challenge lies in handling leap years. Help on this matter would be greatly appreciated.
$('.changeYear').click(function() {
var appointments = [];
for (var i = 1; i <= 22; i++) {
var date = $('#tr-fix-tag-' + i).val();
if (date !== "") {
var splittedDate = date.substr(5).split('.');
appointments.push(new Date(splittedDate[2], splittedDate[1] - 1, splittedDate[0]));
}
}
var counter = 1;
$.each(appointments, function() {
var field = $('#tr-fix-tag-' + counter);
var date = $(this)[0];
var newDate = new Date(date.setFullYear(date.getFullYear() + 1));
if (isSchaltjahr(newDate.getFullYear()))
field.val(formatDate(new Date(newDate.setDate(newDate.getDate() - 2))));
else
field.val(formatDate(new Date(newDate.setDate(newDate.getDate() - 1))));
counter++;
});
});