Last active
August 31, 2019 00:03
-
-
Save saetia/b5ad096331d0d719a6f560b6af872d7a to your computer and use it in GitHub Desktop.
is_federal_holiday
This file contains hidden or 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 | |
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