Skip to content

Commit

Permalink
add logic for juneteenth
Browse files Browse the repository at this point in the history
  • Loading branch information
arcdigital committed Jan 23, 2024
1 parent a969bb7 commit a8185e8
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/Countries/UnitedStates.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ public function countryCode(): string
return 'us';
}

/** @return array<string, CarbonImmutable> */
protected function allHolidays(int $year): array
{
return array_merge([
$holidays = array_merge([
'New Year\'s Day' => '01-01',
'Juneteenth National Independence Day' => '06-19',
'Independence Day' => '07-04',
'Veterans Day' => '11-11',
'Christmas' => '12-25',
], $this->variableHolidays($year));

if ($year >= 2021) {
$holidays['Juneteenth National Independence Day'] = '06-19';
}

return $holidays;
}

/** @return array<string, CarbonImmutable> */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"name": "New Year's Day",
"date": "2020-01-01"
},
{
"name": "Martin Luther King Day",
"date": "2020-01-20"
},
{
"name": "Presidents' Day",
"date": "2020-02-17"
},
{
"name": "Memorial Day",
"date": "2020-05-25"
},
{
"name": "Independence Day",
"date": "2020-07-04"
},
{
"name": "Labor Day",
"date": "2020-09-07"
},
{
"name": "Columbus Day",
"date": "2020-10-12"
},
{
"name": "Veterans Day",
"date": "2020-11-11"
},
{
"name": "Thanksgiving",
"date": "2020-11-26"
},
{
"name": "Christmas",
"date": "2020-12-25"
}
]
15 changes: 14 additions & 1 deletion tests/Countries/UnitedStatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Carbon\CarbonImmutable;
use Spatie\Holidays\Holidays;

it('can calculate united states holidays', function () {
it('can calculate united states holidays after 2021', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');

$holidays = Holidays::for(country: 'us')->get();
Expand All @@ -17,3 +17,16 @@
expect(formatDates($holidays))->toMatchSnapshot();

});

it('can calculate united states holidays before 2021', function () {
CarbonImmutable::setTestNowAndTimezone('2020-01-01');

$holidays = Holidays::for(country: 'us')->get();

expect($holidays)
->toBeArray()
->not()->toBeEmpty();

expect(formatDates($holidays))->toMatchSnapshot();

});

0 comments on commit a8185e8

Please sign in to comment.