-
- // The function returns the number of business days between two dates skipping holidays.
- private function getWorkingDays($startDate, $endDate, $holidays) {
- // TODO: this function needs a fix, as it assumes Sat + Sun weekends,
- // and will not work properly for other week types (ex. Arabic weeks).
-
- // do strtotime calculations just once
- $endDate = strtotime($endDate);
- $startDate = strtotime($startDate);
-
- //The total number of days between the two dates. We compute the no. of seconds and divide it to 60*60*24
- //We add one to inlude both dates in the interval.
- $days = ($endDate - $startDate) / 86400 + 1;
-
- $noOfFullWeeks = floor($days / 7);
- $noOfRemainingDays = fmod($days, 7);
-
- //It will return 1 if it's Monday,.. ,7 for Sunday
- $firstDayofWeek = date("N", $startDate);
- $lastDayofWeek = date("N", $endDate);
-
- //---->The two can be equal in leap years when february has 29 days, the equal sign is added here
- //In the first case the whole interval is within a week, in the second case the interval falls in two weeks.
- if ($firstDayofWeek <= $lastDayofWeek) {
- if ($firstDayofWeek <= 6 && 6 <= $lastDayofWeek) {
- $noOfRemainingDays--;
- }
-
- if ($firstDayofWeek <= 7 && 7 <= $lastDayofWeek) {
- $noOfRemainingDays--;
- }
- }
- else {
- // (edit by Tokes to fix an edge case where the start day was a Sunday
- // and the end day was NOT a Saturday)
-
- // the day of the week for start is later than the day of the week for end
- if ($firstDayofWeek == 7) {
- // if the start date is a Sunday, then we definitely subtract 1 day
- $noOfRemainingDays--;