generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
964e741
commit 95f9772
Showing
4 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class UnitedStates extends Country | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'us'; | ||
} | ||
|
||
protected function allHolidays(int $year): array | ||
{ | ||
$holidays = array_merge([ | ||
'New Year\'s Day' => '01-01', | ||
'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> */ | ||
protected function variableHolidays(int $year): array | ||
{ | ||
$martinLutherKingDay = new CarbonImmutable("third monday of January $year", 'America/Los_Angeles'); | ||
$presidentsDay = new CarbonImmutable("third monday of February $year", 'America/Los_Angeles'); | ||
$memorialDay = new CarbonImmutable("last monday of May $year", 'America/Los_Angeles'); | ||
$laborDay = new CarbonImmutable("first monday of September $year", 'America/Los_Angeles'); | ||
$columbusDay = new CarbonImmutable("second monday of October $year", 'America/Los_Angeles'); | ||
$thanksgiving = new CarbonImmutable("fourth thursday of November $year", 'America/Los_Angeles'); | ||
|
||
return [ | ||
'Martin Luther King Day' => $martinLutherKingDay, | ||
'Presidents\' Day' => $presidentsDay, | ||
'Memorial Day' => $memorialDay, | ||
'Labor Day' => $laborDay, | ||
'Columbus Day' => $columbusDay, | ||
'Thanksgiving' => $thanksgiving, | ||
]; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...pshots/Countries/UnitedStatesTest/it_can_calculate_united_states_holidays_after_2021.snap
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
[ | ||
{ | ||
"name": "New Year's Day", | ||
"date": "2024-01-01" | ||
}, | ||
{ | ||
"name": "Martin Luther King Day", | ||
"date": "2024-01-15" | ||
}, | ||
{ | ||
"name": "Presidents' Day", | ||
"date": "2024-02-19" | ||
}, | ||
{ | ||
"name": "Memorial Day", | ||
"date": "2024-05-27" | ||
}, | ||
{ | ||
"name": "Juneteenth National Independence Day", | ||
"date": "2024-06-19" | ||
}, | ||
{ | ||
"name": "Independence Day", | ||
"date": "2024-07-04" | ||
}, | ||
{ | ||
"name": "Labor Day", | ||
"date": "2024-09-02" | ||
}, | ||
{ | ||
"name": "Columbus Day", | ||
"date": "2024-10-14" | ||
}, | ||
{ | ||
"name": "Veterans Day", | ||
"date": "2024-11-11" | ||
}, | ||
{ | ||
"name": "Thanksgiving", | ||
"date": "2024-11-28" | ||
}, | ||
{ | ||
"name": "Christmas", | ||
"date": "2024-12-25" | ||
} | ||
] |
42 changes: 42 additions & 0 deletions
42
...shots/Countries/UnitedStatesTest/it_can_calculate_united_states_holidays_before_2021.snap
This file contains 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
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" | ||
} | ||
] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Tests\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
use Spatie\Holidays\Holidays; | ||
|
||
it('can calculate united states holidays after 2021', function () { | ||
CarbonImmutable::setTestNowAndTimezone('2024-01-01'); | ||
|
||
$holidays = Holidays::for(country: 'us')->get(); | ||
|
||
expect($holidays) | ||
->toBeArray() | ||
->not()->toBeEmpty(); | ||
|
||
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(); | ||
|
||
}); |