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
Showing
3 changed files
with
79 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,38 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class Canada extends Country | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'ca'; | ||
} | ||
|
||
// These 5 statutory holidays are the only constant among all provinces | ||
// All other holidays vary from province to province. | ||
|
||
protected function allHolidays(int $year): array | ||
{ | ||
return array_merge([ | ||
'New Year\'s Day' => '01-01', | ||
'Canada Day' => '07-05', | ||
'Christmas Day' => '12-25', | ||
], $this->variableHolidays($year)); | ||
} | ||
|
||
/** @return array<string, string|CarbonImmutable> */ | ||
protected function variableHolidays(int $year): array | ||
{ | ||
$labourDay = new CarbonImmutable("first monday of september {$year}"); | ||
|
||
$easter = $this->easter($year); | ||
|
||
return [ | ||
'Good Friday' => $easter->subDays(2), | ||
'Labour Day' => $labourDay, | ||
]; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
tests/.pest/snapshots/Countries/CanadaTest/it_can_calculate_canadian_holidays.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,22 @@ | ||
[ | ||
{ | ||
"name": "New Year's Day", | ||
"date": "2024-01-01" | ||
}, | ||
{ | ||
"name": "Good Friday", | ||
"date": "2024-03-29" | ||
}, | ||
{ | ||
"name": "Canada Day", | ||
"date": "2024-07-05" | ||
}, | ||
{ | ||
"name": "Labour Day", | ||
"date": "2024-09-02" | ||
}, | ||
{ | ||
"name": "Christmas Day", | ||
"date": "2024-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,19 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Tests\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
use Spatie\Holidays\Holidays; | ||
|
||
it('can calculate canadian holidays', function () { | ||
CarbonImmutable::setTestNowAndTimezone('2024-01-01'); | ||
|
||
$holidays = Holidays::for(country: 'ca')->get(); | ||
|
||
expect($holidays) | ||
->toBeArray() | ||
->not()->toBeEmpty(); | ||
|
||
expect(formatDates($holidays))->toMatchSnapshot(); | ||
|
||
}); |