It would take significant refactoring, but it might be nice to be able to add more information within the holiday configuration files to make it easier to display the actual purpose of a business being closed on a specific date and to override specific default dates.
The other benefit of the following proposal is that additional attributes could be added in the future without any breaking changes as long as the setHoliday parser just skips unrecognized attributes.
<?php
return array(
'newyearsday' => [
'date' => Carbon::parse("January 1 $year")->format('d/m'),
'holiday' => [
'en' => 'New Year\'s Day',
],
'observed' => true,
],
'mlkday' => [
'date' => Carbon::parse("third Monday of January $year")->format('d/m'),
'holiday' => [
'en' => 'Martin Luther King Jr. Day',
],
'observed' => true,
],
'easter' => [
'date' => Carbon::createFromDate($year, 3, 21)->addDays(easter_days($year))->format('d/m'),
'holiday' => [
'en' => 'Easter Sunday',
],
'observed' => false,
],
'memorialday' => [
'date' => Carbon::parse("last Monday of May $year")->format('d/m'),
'holiday' => [
'en' => 'Memorial Day',
],
'observed' => true,
],
'independenceday' => [
'date' => Carbon::parse("July 4 $year")->format('d/m'),
'holiday' => [
'en' => 'Independence Day',
],
'observed' => true,
],
'laborday' => [
'date' => Carbon::parse("first Monday of September $year")->format('d/m'),
'holiday' => [
'en' => 'Labor Day',
],
'observed' => true,
],
'thanksgiving' => [
'date' => Carbon::parse("fourth Thursday of November $year")->format('d/m'),
'holiday' => [
'en' => 'Thanksgiving',
],
'observed' => true,
],
'christmasday' => [
'date' => Carbon::parse("December 25 $year")->format('d/m'),
'holiday' => [
'de' => 'Weihnachtstag',
'en' => 'Christmas Day',
'es' => 'Día de Navidad',
'fr' => 'Le jour de Noël',
],
'observed' => true,
]);
Carbon::setHolidaysRegion('us-national');
Carbon::parse('2018-01-15')->isHoliday(true) // 'Martin Luther King Jr. Day' for 2018
Carbon::parse('2018-01-21')->isHoliday(true) // false for 2018
Carbon::parse('2019-01-15')->isHoliday(true) // false for 2019
Carbon::parse('2019-01-21')->isHoliday(true) // 'Martin Luther King Jr. Day' for 2019
Carbon::isHoliday(true) // (str) 'Holiday Name' if today is a holiday, (boolean) false if it is not a holiday
The purpose of using a 'slug' key for the array items is to enable a feature similar to ignoreHoliday('christmas')
or observeHoliday('arborday')
. It would be a great way to use default national holidays while still allowing easy overrides for businesses that might be open on some of those days.
As an aside, Easter was hell to calculate until I saw the php easter_days() function. :-)