Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- date_default_timezone_set('Europe/Tallinn');
- $year = 2011;
- for ($month = 1; $month <= 12; ++$month) {
- list($basePayday, $bonusPayday) = getPaydays($year, $month);
- print($basePayday->format('l, d.m.Y') . "\t\t" .
- $bonusPayday->format('l, d.m.Y') . "\n");
- }
- function isWeekend($date) {
- $weekday = $date->format('l');
- return ($weekday == 'Sunday' || $weekday == 'Saturday');
- }
- function getPaydays($year, $month) {
- $date = new DateTime();
- // Compute the bonus payday.
- $date->setDate($year, $month, 15);
- if (isWeekend($date)) {
- $date->modify('next Wednesday');
- }
- $bonusPayday = clone $date;
- // Compute base salary payday.
- $date->modify('last day of this month');
- if (isWeekend($date)) {
- $date->modify('previous Friday');
- }
- $basePayday = $date;
- return array($basePayday, $bonusPayday);
- }
Add Comment
Please, Sign In to add comment