View Single Post
  #2 (permalink)  
Old 09-02-2007, 07:13 PM
Elemental's Avatar
Elemental Elemental is offline
Senior Member
 
Join Date: Jul 2007
Posts: 119
Default

The easiest solution I can think of off the top of my head is to check the weekday and increment if the days are weekends.

ie.
Code:
//pseudocode, I didn't test this, its just concept

function addWorkDays(startDate, numDays) {
    $numDaysPadding = 0;
 
    for ($i = 0; $i < numDays; $i++) {
        if ( $startDate + ($i +1) == "Saturday" ||
              $startDate + ($i +1) == "Sunday")  {
             $numDaysPadding++;
        }       
    }
    $numDays += $numDaysPadding;
    
    return $startDate + $numDays;
}

Essentially, you increment the number of days your adding if you encounter a weekend day. Zend_Date can return the actual day of the week via ->getWeekday(). This returns an int which is mapped to the day of the week:
0 => Sunday
1=> Monday
2 => Tuesday
3 => Wednesday
....
6 => Saturday


hope that helps...
Reply With Quote