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
USHolidays\Carbon;
re 'path/to/geoffreyrose/Carbon.php';
use USHolidays\Carbon;
$carbon = Carbon::create(2020, 1, 1);
$holidays = $carbon->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
// }
// ...
// ]
$carbon = Carbon::create(2020, 5, 28);
$holidays = $carbon->getHolidaysInDays(300, 'all');
// or
$holidays = $carbon->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
// },
// ...
// ]
$carbon = Carbon::create(2020, 8, 18);
$holidays = $carbon->getHolidaysInYears(1, 'all');
// or
$holidays = $carbon->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
// },
// ...
// ]
$carbon = Carbon::create(2020, 1, 1);
$carbon->getAprilFoolsDayHoliday();
// {
// "name": "April Fool's Day",
// "date": "2020-04-01 00:00:00",
// "bank_holiday": false
// "days_away": 91
// }
$carbon->getAprilFoolsDayHoliday();
$carbon->getArmedForcesDayHoliday();
$carbon->getAshWednesdayHoliday();
$carbon->getBlackFridayHoliday();
$carbon->getChristmasDayHoliday();
$carbon->getChristmasEveHoliday();
$carbon->getCincoDeMayoHoliday();
$carbon->getColumbusDayHoliday();
$carbon->getCyberMondayHoliday();
$carbon->getDaylightSavingEndHoliday();
$carbon->getDaylightSavingStartHoliday();
$carbon->getEarthDayHoliday();
$carbon->getEasterHoliday();
$carbon->getFathersDayHoliday();
$carbon->getFlagDayHoliday();
$carbon->getGoodFridayHoliday();
$carbon->getGroundhogDayHoliday();
$carbon->getHalloweenHoliday();
$carbon->getHanukkahHoliday();
$carbon->getIndependenceDayHoliday();
$carbon->getIndigenousPeoplesDayHoliday();
$carbon->getJuneteenthHoliday();
$carbon->getKwanzaaHoliday();
$carbon->getLaborDayHoliday();
$carbon->getMLKDayHoliday();
$carbon->getMemorialDayHoliday();
$carbon->getMothersDayHoliday();
$carbon->getNewYearsDayHoliday();
$carbon->getNewYearsEveHoliday();
$carbon->getOrthodoxEasterHoliday();
$carbon->getPalmSundayHoliday();
$carbon->getPassoverHoliday();
$carbon->getPatriotDayHoliday();
$carbon->getPearlHarborRemembranceDayHoliday();
$carbon->getPresidentsDayHoliday();
$carbon->getRoshHashanahHoliday();
$carbon->getStPatricksDayHoliday();
$carbon->getTaxDayHoliday();
$carbon->getThanksgivingHoliday();
$carbon->getValentinesDayHoliday();
$carbon->getVeteransDayHoliday();
$carbon->getYomKippurHoliday();
$carbon = new Carbon();
$carbon = Carbon::create(2018, 12, 25);
$carbon->isHoliday(); // bool (true)
$carbon = Carbon::create(2020, 1, 1); // New Years Day - Wednesday
$carbon->isBankHoliday(); // boolean (true)
$carbon = Carbon::create(2020, 1, 2);
$carbon->isBankHoliday(); // boolean (false)
$carbon = Carbon::create(2018, 03, 17); // St Patrick's Day
$carbon->isBankHoliday(); // boolean (false)
$carbon = Carbon::create(2018, 12, 25); // Christmas - Tuesday
$carbon->isBankHoliday(); // boolean (true)
$carbon = Carbon::create(2016, 12, 25); // Christmas - Sunday
$carbon->isBankHoliday(); // boolean (false)
$carbon = Carbon::create(2016, 12, 26); // Monday
$carbon->isBankHoliday(); // boolean (true)
$carbon = Carbon::create(2021, 12, 25); // Christmas - Saturday
$carbon->isBankHoliday(); // boolean (false)
$carbon = Carbon::create(2021, 12, 24); // Friday
$carbon->isBankHoliday(); // boolean (false)
$carbon = Carbon::create(2020, 1, 1); // New Years Day - Wednesday
$carbon->isFederalHoliday(); // boolean (true)
$carbon = Carbon::create(2020, 1, 2);
$carbon->isFederalHoliday(); // boolean (false)
$carbon = Carbon::create(2018, 03, 17); // St Patrick's Day
$carbon->isFederalHoliday(); // boolean (false)
$carbon = Carbon::create(2018, 12, 25); // Christmas - Tuesday
$carbon->isFederalHoliday(); // boolean (true)
$carbon = Carbon::create(2016, 12, 25); // Christmas - Sunday
$carbon->isFederalHoliday(); // boolean (false)
$carbon = Carbon::create(2016, 12, 26); // Monday
$carbon->isFederalHoliday(); // boolean (true)
$carbon = Carbon::create(2021, 12, 25); // Christmas - Saturday
$carbon->isFederalHoliday(); // boolean (false)
$carbon = Carbon::create(2021, 12, 24); // Friday
$carbon->isFederalHoliday(); // boolean (true)
$carbon = Carbon::create(2018, 12, 31);
$carbon->getHolidayName(); // New Year's Eve
$carbon = new Carbon();
$carbon->addHoliday([
'name' => "Spongebob's Birthday",
'date' => Carbon::create(1986, 7, 14),
'bank_holiday' => false
]);
$carbon->addHoliday([
'name' => "Q1 Tax Payments",
'date' => function() use($carbon) {
$q1 = Carbon::create($carbon->year, 4, 15, 0, 0, 0);
if($q1->isBankHoliday()) {
$q1->addDay();
if($q1->isWeekend()) {
$q1->next(Carbon::MONDAY);
}
}
if($q1->isWeekend()) {
$q1->next(Carbon::MONDAY);
}
if($q1 < $carbon) {
$q1 = Carbon::create($carbon->year + 1, 4, 15, 0, 0, 0);
if($q1->isBankHoliday()) {
$q1->addDay();
if($q1->isWeekend()) {
$q1->next(Carbon::MONDAY);
}
}
if($q1->isWeekend()) {
$q1->next(Carbon::MONDAY);
}
}
if($q1->isBankHoliday()) {
$q1->addDay();
}
return $q1;
},
'bank_holiday' => false
]);
$carbon = Carbon::create(2016, 12, 25); // Sunday
$carbon->getHolidayName(); // Christmas Day
$carbon = Carbon::create(2016, 12, 26); // Monday
$carbon->getHolidayName(); // Christmas Day (Observed), Kwanzaa