PHP code example of geoffreyrose / us-holidays
1. Go to this page and download the library: Download geoffreyrose/us-holidays library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
geoffreyrose / us-holidays example snippets
use USHolidays\USHolidays;
...
$holidays = USHolidays::create(2020, 1, 1);
$holidays = $holidays->getHolidaysByYear();
$holidays = USHolidays::getHolidaysByYear();
$holidays = USHolidays::create(2020, 1, 1);
$holidays = $holidays->getHolidaysByYear('all');
// [
// {
// "name": "New Year's Day", // string
// "date": "2020-01-01 00:00:00", // DateTime object
// "bank_holiday": true, // boolean
// "days_away": 0, // int
// },
// {
// "name": "Martin Luther King Jr. Day", // string
// "date": "2020-01-20 00:00:00", // DateTime object
// "bank_holiday": true, // boolean
// "days_away": 19 // int
// }
// ...
// ]
$holidays = USHolidays::create(2020, 5, 28);
$holidays = $holidays->getHolidaysInDays(300, 'all');
// or
$holidays = $holidays->getHolidaysInDays(300);
// [
// {
// "name": "Flag Day", // string
// "date": "2020-06-14 00:00:00", // DateTime object
// "bank_holiday": false, // boolean
// "days_away": 17 // int
// }, {
// "name": "Juneteenth", // string
// "date": "2020-06-19 00:00:00", // DateTime object
// "bank_holiday": false, // boolean
// "days_away": 22 // int
// },
// ...
// ]
$holidays = USHolidays::create(2020, 8, 18);
$holidays = $holidays->getHolidaysInYears(1, 'all');
// or
$holidays = $holidays->getHolidaysInYears(1);
// [
// {
// "name": "Labor Day", // string
// "date": "2020-09-07 00:00:00", // DateTime object
// "bank_holiday": true,// boolean
// "days_away": 20 // int
// }, {
// "name": "Patriot Day", // string
// "date": "2020-09-11 00:00:00", // DateTime object
// "bank_holiday": false, // boolean
// "days_away": 24 // int
// },
// ...
// ]
$holidays = USHolidays::create(2020, 1, 1);
$holidays->getAprilFoolsDayHoliday();
// {
// "name": "April Fool's Day",
// "date": "2020-04-01 00:00:00",
// "bank_holiday": false
// "days_away": 91
// }
$holidays->getAprilFoolsDayHoliday();
$holidays->getArmedForcesDayHoliday();
$holidays->getAshWednesdayHoliday();
$holidays->getBlackFridayHoliday();
$holidays->getChristmasDayHoliday();
$holidays->getChristmasEveHoliday();
$holidays->getCincoDeMayoHoliday();
$holidays->getColumbusDayHoliday();
$holidays->getCyberMondayHoliday();
$holidays->getDaylightSavingEndHoliday();
$holidays->getDaylightSavingStartHoliday();
$holidays->getEarthDayHoliday();
$holidays->getEasterHoliday();
$holidays->getFathersDayHoliday();
$holidays->getFlagDayHoliday();
$holidays->getGoodFridayHoliday();
$holidays->getGroundhogDayHoliday();
$holidays->getHalloweenHoliday();
$holidays->getHanukkahHoliday();
$holidays->getIndependenceDayHoliday();
$holidays->getIndigenousPeoplesDayHoliday();
$holidays->getJuneteenthHoliday();
$holidays->getKwanzaaHoliday();
$holidays->getLaborDayHoliday();
$holidays->getMLKDayHoliday();
$holidays->getMemorialDayHoliday();
$holidays->getMothersDayHoliday();
$holidays->getNewYearsDayHoliday();
$holidays->getNewYearsEveHoliday();
$holidays->getOrthodoxEasterHoliday();
$holidays->getPalmSundayHoliday();
$holidays->getPassoverHoliday();
$holidays->getPatriotDayHoliday();
$holidays->getPearlHarborRemembranceDayHoliday();
$holidays->getPresidentsDayHoliday();
$holidays->getRoshHashanahHoliday();
$holidays->getStPatricksDayHoliday();
$holidays->getTaxDayHoliday();
$holidays->getThanksgivingHoliday();
$holidays->getValentinesDayHoliday();
$holidays->getVeteransDayHoliday();
$holidays->getYomKippurHoliday();
$holidays = USHolidays::create(2018, 12, 25);
$holidays->isHoliday(); // bool (true)
$holidays = USHolidays::create(2020, 1, 1); // New Years Day - Wednesday
$holidays->isBankHoliday(); // boolean (true)
$holidays = USHolidays::create(2020, 1, 2);
$holidays->isBankHoliday(); // boolean (false)
$holidays = USHolidays::create(2018, 03, 17); // St Patrick's Day
$holidays->isBankHoliday(); // boolean (false)
$holidays = USHolidays::create(2018, 12, 25); // Christmas - Tuesday
$holidays->isBankHoliday(); // boolean (true)
$holidays = USHolidays::create(2016, 12, 25); // Christmas - Sunday
$holidays->isBankHoliday(); // boolean (false)
$holidays = USHolidays::create(2016, 12, 26); // Monday
$holidays->isBankHoliday(); // boolean (true)
$holidays = USHolidays::create(2021, 12, 25); // Christmas - Saturday
$holidays->isBankHoliday(); // boolean (false)
$holidays = USHolidays::create(2021, 12, 24); // Friday
$holidays->isBankHoliday(); // boolean (false)
$holidays = USHolidays::create(2020, 1, 1); // New Years Day - Wednesday
$holidays->isFederalHoliday(); // boolean (true)
$holidays = USHolidays::create(2020, 1, 2);
$holidays->isFederalHoliday(); // boolean (false)
$holidays = USHolidays::create(2018, 03, 17); // St Patrick's Day
$holidays->isFederalHoliday(); // boolean (false)
$holidays = USHolidays::create(2018, 12, 25); // Christmas - Tuesday
$holidays->isFederalHoliday(); // boolean (true)
$holidays = USHolidays::create(2016, 12, 25); // Christmas - Sunday
$holidays->isFederalHoliday(); // boolean (false)
$holidays = USHolidays::create(2016, 12, 26); // Monday
$holidays->isFederalHoliday(); // boolean (true)
$holidays = USHolidays::create(2021, 12, 25); // Christmas - Saturday
$holidays->isFederalHoliday(); // boolean (false)
$holidays = USHolidays::create(2021, 12, 24); // Friday
$holidays->isFederalHoliday(); // boolean (true)
$holidays = USHolidays::create(2018, 12, 31);
$holidays->getHolidayName(); // New Year's Eve
$holidays->addHoliday([
'name' => "Spongebob's Birthday",
'date' => USHolidays::create(1986, 7, 14),
'bank_holiday' => false
]);
$holidays->addHoliday([
'name' => "Q1 Tax Payments",
'date' => function() use($holidays) {
$q1 = USHolidays::create($holidays->year, 4, 15, 0, 0, 0);
if($q1->isBankHoliday()) {
$q1->addDay();
if($q1->isWeekend()) {
$q1->next(USHolidays::MONDAY);
}
}
if($q1->isWeekend()) {
$q1->next(USHolidays::MONDAY);
}
if($q1 < $holidays) {
$q1 = USHolidays::create($holidays->year + 1, 4, 15, 0, 0, 0);
if($q1->isBankHoliday()) {
$q1->addDay();
if($q1->isWeekend()) {
$q1->next(USHolidays::MONDAY);
}
}
if($q1->isWeekend()) {
$q1->next(USHolidays::MONDAY);
}
}
if($q1->isBankHoliday()) {
$q1->addDay();
}
return $q1;
},
'bank_holiday' => false
]);
$holidays = USHolidays::create(2016, 12, 25); // Sunday
$holidays->getHolidayName(); // Christmas Day
$holidays = USHolidays::create(2016, 12, 26); // Monday
$holidays->getHolidayName(); // Christmas Day (Observed), Kwanzaa