"jours ouvrés" (Mon-Fri), * false => "jours ouvrables" (Mon-Sat, Sunday excluded) */ public function countWorkingDays( DateTimeImmutable $start, DateTimeImmutable $end, ?HalfDay $startHalfDay = null, ?HalfDay $endHalfDay = null, bool $workingDaysOnly = true, ): float { $start = $start->setTime(0, 0); $end = $end->setTime(0, 0); if ($end < $start) { return 0.0; } $days = 0.0; $period = new DatePeriod($start, new DateInterval('P1D'), $end->modify('+1 day')); foreach ($period as $day) { $weekday = (int) $day->format('N'); // 1 (Mon) .. 7 (Sun) if (7 === $weekday) { continue; // Sunday: never counted } if (6 === $weekday && $workingDaysOnly) { continue; // Saturday: only counted for "jours ouvrables" } if ($this->holidayProvider->isHoliday($day)) { continue; } ++$days; } if ($days <= 0.0) { return 0.0; } if (null !== $startHalfDay) { $days -= 0.5; } if (null !== $endHalfDay) { $days -= 0.5; } return max(0.0, $days); } }