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.
Merge pull request #147 from amitsamtani/feature/add-panama-holidays
Feature/add panama holidays
- Loading branch information
Showing
3 changed files
with
197 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,93 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class Panama extends Country | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'pa'; | ||
} | ||
|
||
/* | ||
* Source: https://www.telemetro.com/nacionales/calendario-feriados-panama-2024-todos-los-dias-no-laborables-y-festivos-n5953115 | ||
*/ | ||
protected function allHolidays(int $year): array | ||
{ | ||
$fixedHolidays = [ | ||
'Año Nuevo' => '01-01', | ||
'Día de los Mártires' => '01-09', | ||
'Día del Trabajador' => '05-01', | ||
'Separación de Panamá de Colombia' => '11-03', | ||
'Día de los Símbolos Patrios' => '11-04', | ||
'Día de Consolidación de la Separación de Panamá con Colombia en Colón' => '11-05', | ||
'Grito de la Independencia' => '11-10', | ||
'Independencia de Panamá de España' => '11-28', | ||
'Día de las Madres' => '12-08', | ||
'Día de los Caídos por la invasión de Estados Unidos a Panamá' => '12-20', | ||
'Navidad' => '12-25', | ||
]; | ||
|
||
return array_merge( | ||
$fixedHolidays, | ||
$this->variableHolidays($year), | ||
$this->calculateBridgeDays($fixedHolidays, $year), | ||
); | ||
} | ||
|
||
/** @return array<string, CarbonImmutable> */ | ||
protected function variableHolidays(int $year): array | ||
{ | ||
$easter = $this->easter($year); | ||
|
||
return [ | ||
'Carnaval (Día 1)' => $easter->subDays(50), | ||
'Carnaval (Día 2)' => $easter->subDays(49), | ||
'Carnaval (Día 3)' => $easter->subDays(48), | ||
'Carnaval (Día 4)' => $easter->subDays(47), | ||
'Jueves Santo' => $easter->subDays(3), | ||
'Viernes Santo' => $easter->subDays(2), | ||
'Sábado de Gloria' => $easter->subDays(1), | ||
]; | ||
} | ||
|
||
/** | ||
* Calculate bridge days for holidays that fall on a Sunday. | ||
* In Panama, these are called "puentes" | ||
* | ||
* Source: https://www.telemetro.com/nacionales/calendario-dias-libres-panama-este-2023-n5825178 | ||
* | ||
* Spanish: | ||
* "Según el artículo 47 del código de trabajo un día es considerado puente cuando la fecha | ||
* establecida para una celebración nacional coincida con un día domingo, el lunes siguiente | ||
* se habilitará como día de descanso semanal obligatorio" | ||
* | ||
* English Translation: | ||
* "According to article 47 of the labor code, a day is considered a bridge when the date | ||
* established for a national celebration to coincide with a Sunday, the following Monday | ||
* will be enabled as a mandatory weekly rest day" | ||
* | ||
* @param array<string, string> $fixedHolidays Array of holidays in the format ['holiday name' => 'mm-dd'] | ||
* @param int $year The year for which to calculate the holidays | ||
* @return array<string, CarbonImmutable> | ||
*/ | ||
protected function calculateBridgeDays(array $fixedHolidays, int $year): array | ||
{ | ||
$holidays = []; | ||
|
||
foreach ($fixedHolidays as $name => $date) { | ||
$holiday = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}"); | ||
|
||
if ($holiday !== false) { | ||
$holidays[$name] = $holiday; | ||
if ($holiday->isSunday()) { | ||
$holidays[$name . ' (Puente)'] = $holiday->addDay(); | ||
} | ||
} | ||
} | ||
|
||
return $holidays; | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
tests/.pest/snapshots/Countries/PanamaTest/it_can_calculate_panama_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,86 @@ | ||
[ | ||
{ | ||
"name": "A\u00f1o Nuevo", | ||
"date": "2024-01-01" | ||
}, | ||
{ | ||
"name": "D\u00eda de los M\u00e1rtires", | ||
"date": "2024-01-09" | ||
}, | ||
{ | ||
"name": "Carnaval (D\u00eda 1)", | ||
"date": "2024-02-10" | ||
}, | ||
{ | ||
"name": "Carnaval (D\u00eda 2)", | ||
"date": "2024-02-11" | ||
}, | ||
{ | ||
"name": "Carnaval (D\u00eda 3)", | ||
"date": "2024-02-12" | ||
}, | ||
{ | ||
"name": "Carnaval (D\u00eda 4)", | ||
"date": "2024-02-13" | ||
}, | ||
{ | ||
"name": "Jueves Santo", | ||
"date": "2024-03-28" | ||
}, | ||
{ | ||
"name": "Viernes Santo", | ||
"date": "2024-03-29" | ||
}, | ||
{ | ||
"name": "S\u00e1bado de Gloria", | ||
"date": "2024-03-30" | ||
}, | ||
{ | ||
"name": "D\u00eda del Trabajador", | ||
"date": "2024-05-01" | ||
}, | ||
{ | ||
"name": "Separaci\u00f3n de Panam\u00e1 de Colombia", | ||
"date": "2024-11-03" | ||
}, | ||
{ | ||
"name": "D\u00eda de los S\u00edmbolos Patrios", | ||
"date": "2024-11-04" | ||
}, | ||
{ | ||
"name": "Separaci\u00f3n de Panam\u00e1 de Colombia (Puente)", | ||
"date": "2024-11-04" | ||
}, | ||
{ | ||
"name": "D\u00eda de Consolidaci\u00f3n de la Separaci\u00f3n de Panam\u00e1 con Colombia en Col\u00f3n", | ||
"date": "2024-11-05" | ||
}, | ||
{ | ||
"name": "Grito de la Independencia", | ||
"date": "2024-11-10" | ||
}, | ||
{ | ||
"name": "Grito de la Independencia (Puente)", | ||
"date": "2024-11-11" | ||
}, | ||
{ | ||
"name": "Independencia de Panam\u00e1 de Espa\u00f1a", | ||
"date": "2024-11-28" | ||
}, | ||
{ | ||
"name": "D\u00eda de las Madres", | ||
"date": "2024-12-08" | ||
}, | ||
{ | ||
"name": "D\u00eda de las Madres (Puente)", | ||
"date": "2024-12-09" | ||
}, | ||
{ | ||
"name": "D\u00eda de los Ca\u00eddos por la invasi\u00f3n de Estados Unidos a Panam\u00e1", | ||
"date": "2024-12-20" | ||
}, | ||
{ | ||
"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,18 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Tests\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
use Spatie\Holidays\Holidays; | ||
|
||
it('can calculate panama holidays', function () { | ||
CarbonImmutable::setTestNowAndTimezone('2024-01-01'); | ||
|
||
$holidays = Holidays::for(country: 'pa')->get(); | ||
|
||
expect($holidays) | ||
->toBeArray() | ||
->not()->toBeEmpty(); | ||
|
||
expect(formatDates($holidays))->toMatchSnapshot(); | ||
}); |