Skip to content

Commit 24e2711

Browse files
committed
added Paraguay holidays class
1 parent c69bcff commit 24e2711

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed

lang/paraguay/en/holidays.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"Año Nuevo": "New Year's Day",
3+
"Día de los Héroes": "Heroes' Day",
4+
"Día del Trabajador": "Labor Day",
5+
"Día de la Independencia Nacional": "Independence Day",
6+
"Paz del Chaco": "Chaco Armistice",
7+
"Fundación de Asunción": "Founding of Asuncion",
8+
"Batalla de Boquerón": "Boqueron Battle Victory Day",
9+
"Virgen de Caacupé": "Virgin of Caacupe Day",
10+
"Navidad": "Christmas",
11+
"Jueves Santo": "Maundy Thursday",
12+
"Viernes Santo": "Good Friday"
13+
}

src/Countries/Paraguay.php

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Spatie\Holidays\Countries;
4+
5+
use Carbon\CarbonImmutable;
6+
use Spatie\Holidays\Concerns\Translatable;
7+
use Spatie\Holidays\Contracts\HasTranslations;
8+
9+
final class Paraguay extends Country implements HasTranslations
10+
{
11+
use Translatable;
12+
13+
public function countryCode(): string
14+
{
15+
return 'py';
16+
}
17+
18+
public function defaultLocale(): string
19+
{
20+
return 'es';
21+
}
22+
23+
protected function allHolidays(int $year): array
24+
{
25+
return array_merge([
26+
'Año Nuevo' => '01-01',
27+
'Día de los Héroes' => '03-01',
28+
'Día del Trabajador' => '05-01',
29+
'Día de la Independencia Nacional' => '05-15',
30+
'Fundación de Asunción' => '08-15',
31+
'Batalla de Boquerón' => '09-29',
32+
'Virgen de Caacupé' => '12-08',
33+
'Navidad' => '12-25',
34+
], $this->variableHolidays($year));
35+
}
36+
37+
/** @return array<string, CarbonImmutable> */
38+
private function variableHolidays(int $year): array
39+
{
40+
$easter = $this->easter($year);
41+
42+
return [
43+
'Paz del Chaco' => $this->chacoArmistice($year),
44+
'Jueves Santo' => $easter->subDays(3),
45+
'Viernes Santo' => $easter->subDays(2),
46+
];
47+
}
48+
49+
private function chacoArmistice(int $year): CarbonImmutable
50+
{
51+
// En 2014, el Día de la Paz del Chaco se trasladó al 16 de junio (Decreto N.º 280 firmado en septiembre del 2013)
52+
// Para años posteriores, la fecha se mantiene como el 12 de junio
53+
return CarbonImmutable::createFromDate($year, 06, $year === 2014 ? 16 : 12);
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[
2+
{
3+
"name": "A\u00f1o Nuevo",
4+
"date": "2024-01-01"
5+
},
6+
{
7+
"name": "D\u00eda de los H\u00e9roes",
8+
"date": "2024-03-01"
9+
},
10+
{
11+
"name": "Jueves Santo",
12+
"date": "2024-03-28"
13+
},
14+
{
15+
"name": "Viernes Santo",
16+
"date": "2024-03-29"
17+
},
18+
{
19+
"name": "D\u00eda del Trabajador",
20+
"date": "2024-05-01"
21+
},
22+
{
23+
"name": "D\u00eda de la Independencia Nacional",
24+
"date": "2024-05-15"
25+
},
26+
{
27+
"name": "Paz del Chaco",
28+
"date": "2024-06-12"
29+
},
30+
{
31+
"name": "Fundaci\u00f3n de Asunci\u00f3n",
32+
"date": "2024-08-15"
33+
},
34+
{
35+
"name": "Batalla de Boquer\u00f3n",
36+
"date": "2024-09-29"
37+
},
38+
{
39+
"name": "Virgen de Caacup\u00e9",
40+
"date": "2024-12-08"
41+
},
42+
{
43+
"name": "Navidad",
44+
"date": "2024-12-25"
45+
}
46+
]

tests/Countries/ParaguayTest.php

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
use Carbon\CarbonImmutable;
4+
use Spatie\Holidays\Holidays;
5+
6+
it('can calculate paraguayan holidays', function (): void {
7+
CarbonImmutable::setTestNow('2024-01-01');
8+
9+
$holidays = Holidays::for(country: 'py')->get();
10+
11+
expect($holidays)
12+
->toBeArray()
13+
->not()->toBeEmpty();
14+
15+
expect(formatDates($holidays))->toMatchSnapshot();
16+
});
17+
18+
it('can get holidays in another locale', function (): void {
19+
CarbonImmutable::setTestNow('2024-01-01');
20+
21+
$holidays = Holidays::for(country: 'py', locale: 'en')->get();
22+
23+
expect($holidays[0]['name'])
24+
->toBe("New Year's Day");
25+
});
26+
27+
it('can calculate Chacho Armistice holiday', function (int $year, int $valid_day, int $invalid_day): void {
28+
CarbonImmutable::setTestNow("$year-01-01");
29+
30+
expect(Holidays::for('py')->isHoliday("$year-06-$valid_day"))->toBeTrue()
31+
->and(Holidays::for('py')->isHoliday("$year-06-$invalid_day"))->toBeFalse();
32+
})->with([
33+
[2012, 12, 16],
34+
[2013, 12, 16],
35+
[2014, 16, 12],
36+
[2015, 12, 16],
37+
[2016, 12, 16],
38+
[2024, 12, 16],
39+
]);

0 commit comments

Comments
 (0)