florianv / business

:date: DateTime calculations in business hours
http://florianv.github.io/business
MIT License
361 stars 25 forks source link

Working day interval manipulation #13

Closed pyrech closed 9 years ago

pyrech commented 9 years ago

Nice work on this project. :)

Business is close to what I need (manipulate a list of working days, excluding public holiday) but for my use case, it lacks of interval operations:

I need to do something like:

// Get the third working days starting from now
$date = $business->add(new \DateTime(), 3);

So I just wonder if this feature could enter in the scope of business?

florianv commented 9 years ago

Thanks :)

To get the third business day starting from now (excluding it) you can do something like:

$n = 3;
$date = new \DateTime();

for ($i = 0; $i < $n; $i++) {
    $date->modify('+1 day');
    $date = $business->closest($date);
}
pyrech commented 9 years ago

Ahah, awesome! Thanks :) Let's use business \o/