The PEAR functions didn't seem to do what I was looking for. I built this
function based on an idea given to me by Daryl Meese.
After much trial and error, it actualy does what I need. My function is
bassed on hours but you can easily change that. It will add or subtract
days.
- Anthony
/* buisinessDays
* Calculates a new date bassed on buisiness hours
* vars: hours to adjust by, timestamp
* returns: adjusted timestamp
*/
function businessDays($hours,$date) {
// this function assumes $date is a business day
$dayHours=7.5; // set how many hours are in a day
// set the days we need to adjust by. there is a one day buffer
$days=(abs($hours/$dayHours))+1;
// weeks
$adjust=604800 * floor($days / 5);
// how many days are left over
$remain=round($days % 5);
// check for negative
if ($hours0) {
// check to see if we will land on a weekend, and make appropriate
adjustment
if (date(w,$date)=$remain) {
$remain +=2;
}
// make the time adjustment, 8640 microseconds in a day, times the
remaining adjustment
$date -=($adjust +(86400 * $remain));
}
else {
// check to see if we will land on a weekend, and make appropriate
adjustment
if ((6-date(w,$date))=$remain) {
$remain+=2;
}
// make the time adjustment, 8640 microseconds in a day, times the
remaining adjustment
$date +=($adjust +(86400 * $remain));
}
return $date;
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php