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.
* added `Paraguay` holidays class * Update comment * Added `Guaraní` translations * Updated tests for Guaraní lang * FIX: Guaraní translation
- Loading branch information
Showing
5 changed files
with
171 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,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" | ||
} |
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,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" | ||
} |
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,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); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
tests/.pest/snapshots/Countries/ParaguayTest/it_can_calculate_paraguayan_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,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" | ||
} | ||
] |
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,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], | ||
]); |