I was modifying the old version to maintain the old date when I started from scratch. As much as I like the old one for its novel approach, I prefer this as it is 10 times faster.
I knew that they occasionally make exceptions for leapyears but I didnt know there was a rule for it, I thought that chaos didnt allow for those kind of accurate predictions, it seems I was wrong. You can make that adjustment if you want. But for most cases it will not matter as it wont be effective in roughly a hundred years in both directions.
Business Day Calcs, this method does not involve looping like I have seen people do.
Code:
Date.prototype.DaysBetweenBusiness = function(){
//Does not account for holidays! LOL
//return -1 if start or end date is not a business day
if(!this.IsWeekDay() || !arguments[0].IsWeekDay())return -1
var intMilDay = 24 * 60 * 60 * 1000;
var intMilWeek = intMilDay * 7;
var intSDay = this.getDay();
var intEDay = arguments[0].getDay();
this.setDate(this.getDate() + 7 - intSDay);
arguments[0].setDate(arguments[0].getDate() - intEDay);
var intMilDif = arguments[0] - this;
var intDaysTotal = Math.floor(intMilDif/intMilDay);
var intWeeks = Math.floor(intMilDif/intMilWeek);
return xD = 5 - intSDay + intEDay + intDaysTotal -(intWeeks*2)
}
Date.prototype.IsWeekDay = function(){
return this.getDay() > 0 && this.getDay() < 6
}
var d1 = new Date("06/6/2005");
var d2 = new Date("06/29/2005");
alert(d1.DaysBetweenBusiness(d2));
Bookmarks