Guest User

Untitled

a guest
Jul 21st, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. <?php
  2.  
  3. date_default_timezone_set('Europe/Tallinn');
  4.  
  5.  
  6. $year = 2011;
  7. for ($month = 1; $month <= 12; ++$month) {
  8. list($basePayday, $bonusPayday) = getPaydays($year, $month);
  9. print($basePayday->format('l, d.m.Y') . "\t\t" .
  10. $bonusPayday->format('l, d.m.Y') . "\n");
  11. }
  12.  
  13.  
  14. function isWeekend($date) {
  15. $weekday = $date->format('l');
  16. return ($weekday == 'Sunday' || $weekday == 'Saturday');
  17. }
  18.  
  19.  
  20. function getPaydays($year, $month) {
  21. $date = new DateTime();
  22.  
  23. // Compute the bonus payday.
  24. $date->setDate($year, $month, 15);
  25. if (isWeekend($date)) {
  26. $date->modify('next Wednesday');
  27. }
  28. $bonusPayday = clone $date;
  29.  
  30. // Compute base salary payday.
  31. $date->modify('last day of this month');
  32. if (isWeekend($date)) {
  33. $date->modify('previous Friday');
  34. }
  35. $basePayday = $date;
  36.  
  37. return array($basePayday, $bonusPayday);
  38. }
Add Comment
Please, Sign In to add comment