Created
January 25, 2011 21:57
-
-
Save erikkaplun/795759 to your computer and use it in GitHub Desktop.
Paydays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Monday, 31.01.2011 Wednesday, 19.01.2011 | |
Monday, 28.02.2011 Tuesday, 15.02.2011 | |
Thursday, 31.03.2011 Tuesday, 15.03.2011 | |
Friday, 29.04.2011 Friday, 15.04.2011 | |
Tuesday, 31.05.2011 Wednesday, 18.05.2011 | |
Thursday, 30.06.2011 Wednesday, 15.06.2011 | |
Friday, 29.07.2011 Friday, 15.07.2011 | |
Wednesday, 31.08.2011 Monday, 15.08.2011 | |
Friday, 30.09.2011 Thursday, 15.09.2011 | |
Monday, 31.10.2011 Wednesday, 19.10.2011 | |
Wednesday, 30.11.2011 Tuesday, 15.11.2011 | |
Friday, 30.12.2011 Thursday, 15.12.2011 | |
Tuesday, 31.01.2012 Wednesday, 18.01.2012 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment