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

Adding Nicaragua Holidays #92

Merged
merged 3 commits into from
Jan 19, 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
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2

[*.snap]
insert_final_newline = false
39 changes: 39 additions & 0 deletions src/Countries/Nicaragua.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class Nicaragua extends Country
{
public function countryCode(): string
{
return 'ni';
}

protected function allHolidays(int $year): array
{
return array_merge([
'Año nuevo' => '01-01',
'Día internacional de los trabajadores' => '05-01',
'Día de las madres' => '05-30',
'Aniversario de la revolución' => '07-19',
'Aniversario de la batalla de san jacinto' => '09-14',
'Aniversario de la independencia' => '09-15',
'Día de la inmaculada concepción' => '12-08',
'Navidad' => '12-25',
], $this->variableHolidays($year));
}

/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$easter = CarbonImmutable::createFromTimestamp(easter_date($year))
->setTimezone('America/Managua');

return [
'Jueves santo' => $easter->subDays(3),
'Viernes santo' => $easter->subDays(2),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"name": "A\u00f1o nuevo",
"date": "2024-01-01"
},
{
"name": "Jueves santo",
"date": "2024-03-27"
},
{
"name": "Viernes santo",
"date": "2024-03-28"
},
{
"name": "D\u00eda internacional de los trabajadores",
"date": "2024-05-01"
},
{
"name": "D\u00eda de las madres",
"date": "2024-05-30"
},
{
"name": "Aniversario de la revoluci\u00f3n",
"date": "2024-07-19"
},
{
"name": "Aniversario de la batalla de san jacinto",
"date": "2024-09-14"
},
{
"name": "Aniversario de la independencia",
"date": "2024-09-15"
},
{
"name": "D\u00eda de la inmaculada concepci\u00f3n",
"date": "2024-12-08"
},
{
"name": "Navidad",
"date": "2024-12-25"
}
]
18 changes: 18 additions & 0 deletions tests/Countries/NicaraguaTest.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 nicaragua holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');

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

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

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