diff --git a/src/Countries/Panama.php b/src/Countries/Panama.php new file mode 100644 index 000000000..04f3c54d8 --- /dev/null +++ b/src/Countries/Panama.php @@ -0,0 +1,93 @@ + '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 */ + 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 $fixedHolidays Array of holidays in the format ['holiday name' => 'mm-dd'] + * @param int $year The year for which to calculate the holidays + * @return array + */ + 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; + } +} diff --git a/tests/.pest/snapshots/Countries/PanamaTest/it_can_calculate_panama_holidays.snap b/tests/.pest/snapshots/Countries/PanamaTest/it_can_calculate_panama_holidays.snap new file mode 100644 index 000000000..cbe9ce887 --- /dev/null +++ b/tests/.pest/snapshots/Countries/PanamaTest/it_can_calculate_panama_holidays.snap @@ -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" + } +] \ No newline at end of file diff --git a/tests/Countries/PanamaTest.php b/tests/Countries/PanamaTest.php new file mode 100644 index 000000000..f848a26f2 --- /dev/null +++ b/tests/Countries/PanamaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +});