Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Andorra Holidays #36

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/Countries/Andorra.php
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),
];
}
}
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"
}
]
18 changes: 18 additions & 0 deletions tests/Countries/AndorraTest.php
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();
});