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 new country Paraguay #254

Merged
merged 5 commits into from
Dec 18, 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
13 changes: 13 additions & 0 deletions lang/paraguay/en/holidays.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"Año Nuevo": "New Year's Day",
"Día de los Héroes": "Heroes' Day",
"Día del Trabajador": "Labor Day",
"Día de la Independencia Nacional": "Independence Day",
"Paz del Chaco": "Chaco Armistice",
"Fundación de Asunción": "Founding of Asuncion",
"Batalla de Boquerón": "Boqueron Battle Victory Day",
"Virgen de Caacupé": "Virgin of Caacupe Day",
"Navidad": "Christmas",
"Jueves Santo": "Maundy Thursday",
"Viernes Santo": "Good Friday"
}
13 changes: 13 additions & 0 deletions lang/paraguay/gn/holidays.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"Año Nuevo": "Ary Pyahu",
"Día de los Héroes": "Ára Marangatukuéra",
"Día del Trabajador": "Ára Mba'apoha Guasu",
"Día de la Independencia Nacional": "Tetã Ñepyrũ Ára",
"Paz del Chaco": "Chaco Ñemombytu'u",
"Fundación de Asunción": "Asunción Ñepyrũ Ára",
"Batalla de Boquerón": "Boquerón Ñorairõ Vy'apavẽ Ára",
"Virgen de Caacupé": "Ka'akupe Tupasy Ára",
"Navidad": "Araity",
"Jueves Santo": "Arapo Jueves Marangatu",
"Viernes Santo": "Arapoteĩ Marangatu"
}
55 changes: 55 additions & 0 deletions src/Countries/Paraguay.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php declare(strict_types=1);

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;
use Spatie\Holidays\Concerns\Translatable;
use Spatie\Holidays\Contracts\HasTranslations;

final class Paraguay extends Country implements HasTranslations
{
use Translatable;

public function countryCode(): string
{
return 'py';
}

public function defaultLocale(): string
{
return 'es';
}

protected function allHolidays(int $year): array
{
return array_merge([
'Año Nuevo' => '01-01',
'Día de los Héroes' => '03-01',
'Día del Trabajador' => '05-01',
'Día de la Independencia Nacional' => '05-15',
'Fundación de Asunción' => '08-15',
'Batalla de Boquerón' => '09-29',
'Virgen de Caacupé' => '12-08',
'Navidad' => '12-25',
], $this->variableHolidays($year));
}

/** @return array<string, CarbonImmutable> */
private function variableHolidays(int $year): array
{
$easter = $this->easter($year);

return [
'Paz del Chaco' => $this->chacoArmistice($year),
'Jueves Santo' => $easter->subDays(3),
'Viernes Santo' => $easter->subDays(2),
];
}

private function chacoArmistice(int $year): CarbonImmutable
{
// In 2014, the Day of Chaco Armistice was moved to June 16th (Decree N.º 280 signed in September 2013)
// For later years, the date remains as June 12th
return CarbonImmutable::createFromDate($year, 06, $year === 2014 ? 16 : 12);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"name": "A\u00f1o Nuevo",
"date": "2024-01-01"
},
{
"name": "D\u00eda de los H\u00e9roes",
"date": "2024-03-01"
},
{
"name": "Jueves Santo",
"date": "2024-03-28"
},
{
"name": "Viernes Santo",
"date": "2024-03-29"
},
{
"name": "D\u00eda del Trabajador",
"date": "2024-05-01"
},
{
"name": "D\u00eda de la Independencia Nacional",
"date": "2024-05-15"
},
{
"name": "Paz del Chaco",
"date": "2024-06-12"
},
{
"name": "Fundaci\u00f3n de Asunci\u00f3n",
"date": "2024-08-15"
},
{
"name": "Batalla de Boquer\u00f3n",
"date": "2024-09-29"
},
{
"name": "Virgen de Caacup\u00e9",
"date": "2024-12-08"
},
{
"name": "Navidad",
"date": "2024-12-25"
}
]
44 changes: 44 additions & 0 deletions tests/Countries/ParaguayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

use Carbon\CarbonImmutable;
use Spatie\Holidays\Holidays;

it('can calculate paraguayan holidays', function (): void {
CarbonImmutable::setTestNow('2024-01-01');

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

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

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

it('can get holidays in another locale', function (): void {
CarbonImmutable::setTestNow('2024-01-01');

$holidays_en = Holidays::for(country: 'py', locale: 'en')->get();

expect($holidays_en[0]['name'])
->toBe("New Year's Day");

$holidays_gn = Holidays::for(country: 'py', locale: 'gn')->get();

expect($holidays_gn[0]['name'])
->toBe("Ary Pyahu");
});

it('can calculate Chacho Armistice holiday', function (int $year, int $valid_day, int $invalid_day): void {
CarbonImmutable::setTestNow("$year-01-01");

expect(Holidays::for('py')->isHoliday("$year-06-$valid_day"))->toBeTrue()
->and(Holidays::for('py')->isHoliday("$year-06-$invalid_day"))->toBeFalse();
})->with([
[2012, 12, 16],
[2013, 12, 16],
[2014, 16, 12],
[2015, 12, 16],
[2016, 12, 16],
[2024, 12, 16],
]);