Modify weekdays php 5.3

Recently I needed to add a certain amount of weekdays onto a date using php 5.3.

I wrote this simple function which has two parameters, the amount of weekdays I want to add and the date I want to add them to as an instance of DateTime as follows:

/**
* @param int $weekDays
* @param DateTime $date
* @return DateTime
*/
public function addWeekdaysToDateTime($weekDays, DateTime $date)
{
    $days = 0;

    //only increase the day count for weekdays
    while ($days < $weekDays) {
        $date->modify("+1 day");

        //if we're now on a weekday, increase the weekday counter
        if (!in_array($date->format("D"), ['Sat', 'Sun'])) {
            $days++;
        }
    }
    return $date;
}

LAMP Developer Team Lead

I’ve only been in my role for 1 year and 9 months but I’ve settled in well as a LAMP developer and I’m well chuffed to have been made a team lead (one of two)! The dev team has grown a bit since I started so it should make it easier for triaging, divvying out projects and handling code reviews etc. – Speaking of which, we’ve been using Review Board with great success so far. It’s got a really nice side-by-side view to display the diff which I find a bit easier on the eye than the ++ – – affair you normally get if you’re going command line.