Skip to content

Instantly share code, notes, and snippets.

@saetia
Last active August 31, 2019 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saetia/b5ad096331d0d719a6f560b6af872d7a to your computer and use it in GitHub Desktop.
Save saetia/b5ad096331d0d719a6f560b6af872d7a to your computer and use it in GitHub Desktop.
is_federal_holiday
<?php
function is_federal_holiday(DateTime $date){
$year = $date->format('Y');
$federal_holidays = array_map(function($date_string) use($year){
$date = new DateTime($date_string . ' ' . $year);
if ($date->format('l') === 'Saturday') $date->modify('-1 day');
if ($date->format('l') === 'Sunday') $date->modify('+1 day');
return $date;
}, [
"january 1", //new year's day
"third monday of january", //martin luther king, jr. day
"third monday of february", //george washington’s birthday
"last monday of may", //memorial day
"july 4", //independence day
"first monday of september", //labor day
"second monday of october", //columbus day
"november 11", //veterans day
"fourth thursday of november", //thanksgiving day
"december 25", //christmas day
]);
return array_filter($federal_holidays, function($federal_holiday) use($date){
return $federal_holiday == $date;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment