Skip to content

Instantly share code, notes, and snippets.

@erikkaplun
Created January 25, 2011 21:57
Show Gist options
  • Save erikkaplun/795759 to your computer and use it in GitHub Desktop.
Save erikkaplun/795759 to your computer and use it in GitHub Desktop.
Paydays
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
<?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