Skip to content

Instantly share code, notes, and snippets.

@rmpel
Last active June 1, 2016 10:20
Show Gist options
  • Save rmpel/2b21652bd6485b617293af00325ad7f8 to your computer and use it in GitHub Desktop.
Save rmpel/2b21652bd6485b617293af00325ad7f8 to your computer and use it in GitHub Desktop.
Dutch off-of-work-holiday-days
<?php
/**
* @class Returns a list of DUTCH holidays on which we brave people stop and do nothing for a day... just 'cause :)
*/
class Holidays {
/**
* Returns all dates on which we Dutch people get a day off of work.
* @param int $year The year for which to get the list of holidays
* @return Array The list of holidays, associative array [holiday name] => [date in d-m-Y format]
*/
public static function getHolidays($year=null)
{
$year = intval( $year ?: date('Y') );
$pasen = easter_date($year);
$holidayList = array(
'1e Paasdag' => date("d-m-Y", $pasen),
'2e Paasdag' => date("d-m-Y", $pasen + 86400),
'Hemelvaart' => date("d-m-Y", $pasen + (86400 * 39)),
'1e Pinksterdag' => date("d-m-Y", $pasen + (86400 * 49)),
'2e Pinksterdag' => date("d-m-Y", $pasen + (86400 * 50)),
'Nieuwsjaarsdag' => "01-01-" . $year,
'Koningsdag' => "27-04-" . $year,
'1e Kerstdag' => "25-12-" . $year,
'2e Kerstdag' => "26-12-" . $year
);
if (0 === $year % 5) {
$holidayList['Bevrijdingsdag'] = "05-05" . $year;
}
return $holidayList;
}
/**
* List the upcoming holidays on which Dutch people get a day off of work
* @return Array The list of holidays, sorted by date, associative array [holiday name] => [date in d-m-Y format]
*/
public static function getUpcomingHolidays()
{
$year = intval( date('Y') );
$this_year = self::getHolidays($year);
$next_year = self::getHolidays($year+1);
$this_year = array_filter($this_year, array('self', '_filter_callback'));
$upcoming = array_merge($next_year, $this_year);
uasort($upcoming, array('self', '_compare_callback'));
return $upcoming;
}
/**
* transform date d-m-Y into a sortable string Ymd
* @param String $in The date in d-m-Y format
* @return String The date in Ymd format
*/
private static function d_m_y_to_ymd( $in ) {
return implode('', array_reverse(explode('-', $in)));
}
/**
* Internal: use as callback for array_filter; returns true for future (or TODAY) holidays
* @param String $date The date in d-m-Y format
* @return boolean true for keep, false for drop
*/
private static function _filter_callback( $date ) {
$today = date('d-m-Y');
return self::d_m_y_to_ymd($date) >= self::d_m_y_to_ymd($today);
}
/**
* Internal: use as callback for uasort
* @param String $date_A The date in d-m-Y format
* @param String $date_B The date in d-m-Y format
* @return mixed The sort-value
* @see http://php.net/strcmp
*/
private static function _compare_callback( $date_A, $date_B ) {
return strcmp(self::d_m_y_to_ymd($date_A),self::d_m_y_to_ymd($date_B));
}
}
/** example use */
$offdays = Holidays::getUpcomingHolidays();
var_dump($offdays);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment