Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. public static function getWorkingDays($startDate, $endDate)
  2. {
  3. $holidays = [
  4. "01-01-2017", // Yılbaşı
  5. "23-04-2017", // 23 Nisan
  6. "01-05-2017", // 1 Mayıs
  7. "19-05-2017", // 19 Mayıs
  8. "24-06-2017", // Ramazan Bayramı Arifesi
  9. "25-06-2017", // 25 Haziran Ramazan Bayramı 1.gün
  10. "26-06-2017", // 26 Haziran Ramazan Bayramı 2.gün
  11. "27-06-2017", // 27 Haziran Ramazan Bayramı 3.gün
  12. "15-07-2017", // 15 Temmuz
  13. "30-08-2017", // 30 Ağustos
  14. "31-08-2017", // Kurban Bayramı Arifesi
  15. "01-09-2017", // Kurban Bayramı 1.gün
  16. "02-09-2017", // Kurban Bayramı 2.gün
  17. "03-09-2017", // Kurban Bayramı 3.gün
  18. "04-09-2017", // Kurban Bayramı 4.gün
  19. "29-10-2017" // 29 Ekim
  20. ];
  21.  
  22. $endDate = strtotime($endDate);
  23. $startDate = strtotime($startDate);
  24.  
  25. $days = ($endDate - $startDate) / 86400 + 1;
  26. $no_full_weeks = floor($days / 7);
  27. $no_remaining_days = fmod($days, 7);
  28.  
  29. $the_first_day_of_week = date("N", $startDate);
  30. $the_last_day_of_week = date("N", $endDate);
  31.  
  32. if ($the_first_day_of_week <= $the_last_day_of_week) {
  33. if ($the_first_day_of_week <= 6 && 6 <= $the_last_day_of_week)
  34. $no_remaining_days--;
  35. if ($the_first_day_of_week <= 7 && 7 <= $the_last_day_of_week)
  36. $no_remaining_days--;
  37. } else {
  38. if ($the_first_day_of_week == 7) {
  39. $no_remaining_days--;
  40. if ($the_last_day_of_week == 6) {
  41. $no_remaining_days--;
  42. }
  43. } else {
  44. $no_remaining_days -= 2;
  45. }
  46. }
  47.  
  48. $workingDays = $no_full_weeks * 5;
  49. if ($no_remaining_days > 0) {
  50. $workingDays += $no_remaining_days;
  51. }
  52.  
  53. foreach ($holidays as $holiday) {
  54. $time_stamp = strtotime($holiday);
  55. if ($startDate <= $time_stamp && $time_stamp <= $endDate && date("N", $time_stamp) != 6 && date("N", $time_stamp) != 7)
  56. $workingDays--;
  57. }
  58.  
  59. return $workingDays;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement