I think it'll be really useful to add the ability to add days but skip out the weekends.
For example:
If it was 15/08/2013 and I wanted to add 2 days to this but skip out the weekend.
It'll return 19/08/2013.
Another example would be if the date was 16/08/2013 and again wanted to add 2 days to this date.
The returned date would again be 19/08/2013 as its added 2 days as expected but missed the weekend as a date that can be returned.
Hope this is understandable?
Yes I understand... the following 4 methods already exist for this.
public function addWeekdays($value)
public function addWeekday()
public function subWeekday()
public function subWeekdays($value)
Yes but these skip over the weekends and then begin the count, what am proposing is a way to make it not skip the weekends but not have has a possible result.
So after adding two days to a date and the day is a weekend, you need it to continue on to the next weekday? Which would always be Monday. So this one statement can accomplish that.
if ($dt->addDays(2)->isWeekend()) $dt->next(Carbon::MONDAY);
I think it would be hard to name a method that explains this logic without it being confused with the current addWeekdays methods. The line above though, is very readable and easy to understand the logic immediately.
Ah nice, didn't notice the next() function. I used the isWeekend() function in a loop. I'll switch to this mentioned though I think as it looks better and doesn't involve looping.
That is the best way. Considering this closed.
Carbon::setWeekendDays([
Carbon::SUNDAY
]);
$date=Carbon::parse("2019-07-05");
$tat=15;
$tat_date=Carbon::parse("2019-07-05")->addWeekdays($tat); dd($tat_date);
giving me 2019-07-20;
:(
@sanketgawde As I tested it on https://try-carbon.herokuapp.com it gaves me the right output: 2019-07-23 00:00:00
If you have an issue, please open a new one as this one is closed and provide enough information so we can reproduce the problem.
Most helpful comment
Yes I understand... the following 4 methods already exist for this.
public function addWeekdays($value)
public function addWeekday()
public function subWeekday()
public function subWeekdays($value)