generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from BurtDS/main
- Loading branch information
Showing
3 changed files
with
115 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,43 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class Andorra extends Country | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'ad'; | ||
} | ||
|
||
/** @return array<string, CarbonImmutable> */ | ||
protected function allHolidays(int $year): array | ||
{ | ||
return array_merge([ | ||
'Any nou' => '01-01', | ||
'Reis' => '01-06', | ||
'Dia de la Constitució' => '03-14', | ||
'Festa del Treball' => '05-01', | ||
'Assumpció' => '08-15', | ||
'Mare de Déu de Meritxell' => '09-08', | ||
'Tots Sants' => '11-01', | ||
'Immaculada Concepció' => '11-08', | ||
'Nadal' => '12-25', | ||
'Sant Esteve' => '12-26', | ||
], $this->variableHolidays($year)); | ||
} | ||
|
||
/** @return array<string, CarbonImmutable> */ | ||
protected function variableHolidays(int $year): array | ||
{ | ||
$easter = CarbonImmutable::createFromTimestamp(easter_date($year)) | ||
->setTimezone('Europe/Brussels'); | ||
|
||
return [ | ||
'Divendres Sant' => $easter->subDays(2), | ||
'Dilluns de Pasqua' => $easter->addDay(), | ||
'Dilluns de Pentecosta' => $easter->addDays(50), | ||
]; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
tests/.pest/snapshots/Countries/AndorraTest/it_can_calculate_andorra_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,54 @@ | ||
[ | ||
{ | ||
"name": "Any nou", | ||
"date": "2024-01-01" | ||
}, | ||
{ | ||
"name": "Reis", | ||
"date": "2024-01-06" | ||
}, | ||
{ | ||
"name": "Dia de la Constituci\u00f3", | ||
"date": "2024-03-14" | ||
}, | ||
{ | ||
"name": "Divendres Sant", | ||
"date": "2024-03-29" | ||
}, | ||
{ | ||
"name": "Dilluns de Pasqua", | ||
"date": "2024-04-01" | ||
}, | ||
{ | ||
"name": "Festa del Treball", | ||
"date": "2024-05-01" | ||
}, | ||
{ | ||
"name": "Dilluns de Pentecosta", | ||
"date": "2024-05-20" | ||
}, | ||
{ | ||
"name": "Assumpci\u00f3", | ||
"date": "2024-08-15" | ||
}, | ||
{ | ||
"name": "Mare de D\u00e9u de Meritxell", | ||
"date": "2024-09-08" | ||
}, | ||
{ | ||
"name": "Tots Sants", | ||
"date": "2024-11-01" | ||
}, | ||
{ | ||
"name": "Immaculada Concepci\u00f3", | ||
"date": "2024-11-08" | ||
}, | ||
{ | ||
"name": "Nadal", | ||
"date": "2024-12-25" | ||
}, | ||
{ | ||
"name": "Sant Esteve", | ||
"date": "2024-12-26" | ||
} | ||
] |
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,18 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Tests\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
use Spatie\Holidays\Holidays; | ||
|
||
it('can calculate andorra holidays', function () { | ||
CarbonImmutable::setTestNowAndTimezone('2024-01-01'); | ||
|
||
$holidays = Holidays::for(country: 'ad')->get(); | ||
|
||
expect($holidays) | ||
->toBeArray() | ||
->not()->toBeEmpty(); | ||
|
||
expect(formatDates($holidays))->toMatchSnapshot(); | ||
}); |