February 25, 2001 - Computing the Next Business Day
February 20, 2001 Computing the Next Business Day Tips: February 2001
Yehuda Shiran, Ph.D.
|
getNextBusinessDay()
, computes the next business day. We take advantage of our function, getDeliveryDateObj(1)
, which forward-computes the date, counting business days only. We just pass the value of 1 to this function (national holidays are counted as business days):
<SCRIPT LANGUAGE="JavaScript">
function getNextBusinessDay() {
return getDeliveryDateObj(1);
}
function getDeliveryDateObj(businessDaysLeftForDelivery) {
var now = new Date();
var dayOfTheWeek = now.getDay();
var calendarDays = businessDaysLeftForDelivery;
var deliveryDay = dayOfTheWeek + businessDaysLeftForDelivery;
if (deliveryDay >= 6) {
businessDaysLeftForDelivery -= 6 - dayOfTheWeek; //deduct this-week days
calendarDays += 2; //count this coming weekend
deliveryWeeks = Math.floor(businessDaysLeftForDelivery / 5); //how many whole weeks?
calendarDays += deliveryWeeks * 2; //two days per weekend per week
}
now.setTime(now.getTime() + calendarDays * 24 * 60 * 60 * 1000);
return now;
}
</SCRIPT>
Click here to find out the next business day.