I'm trying to determine four dates based on the current date -- the beginning of the current pay period to today, and then then start and end dates of the previous pay period -- and I'm having trouble finding the correct execution.
To me it makes sense to have an object with four properties like payPd.currentStart, payPd.currentEnd, payPd.priorStart, and payPd.priorEnd.
Currently I'm working backward from the .currentEnd, which is today, and subtracting days until it's Monday on an odd week -- pay periods are two weeks long:
var dt = new Date();
Date.prototype.getWeek = function () {
var onejan = new Date(this.getFullYear(), 0, 1);
return Math.ceil((((this - onejan) / 86400000) + onejan.getDay() + 1) / 7);
}
var currentStart = '';
var currentEnd = new Date();
var priorStart = '';
var priorEnd = '';
function ppdStart(currentEnd){
var inDate = currentEnd;
while (inDate.getWeek() % 2 !== 0 || inDate.getDay() !== 1) {
inDate.setDate(inDate.getDate() - 1);
}
return outDate;
}
So the question is, can I define one property, then define the next property as a function of that one (next odd Monday before today), and so on with the rest? Would I want a callback function, or a get/set? I'm not sure where to go next.
Thanks to all of you in the Javascript community I'm just now joining.