From db5cdb912efa775bedb6580ac17468755085e901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alvaro=20Le=C3=B3n=20Torres?= Date: Wed, 17 Jan 2024 19:16:06 -0500 Subject: [PATCH 1/5] Adding Colombia Holidays Added the Colombia's holidays. There's a situation with some holidays due to the "Emiliany Law" they are moved to the following monday. --- src/Countries/Colombia.php | 59 +++++++++++++++ .../it_can_calculate_colombia_holidays.snap | 74 +++++++++++++++++++ tests/Countries/ColombiaTest.php | 18 +++++ 3 files changed, 151 insertions(+) create mode 100644 src/Countries/Colombia.php create mode 100644 tests/.pest/snapshots/Countries/ColombiaTest/it_can_calculate_colombia_holidays.snap create mode 100644 tests/Countries/ColombiaTest.php diff --git a/src/Countries/Colombia.php b/src/Countries/Colombia.php new file mode 100644 index 000000000..1004e333f --- /dev/null +++ b/src/Countries/Colombia.php @@ -0,0 +1,59 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'Año Nuevo' => '01-01', + 'Día del Trabajo' => '05-01', + 'Día de la independencia' => '07-20', + 'Batalla de Boyacá' => '08-07', + 'Inmaculada Concepción' => '12-08', + 'Navidad' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('America/Bogota'); + + return [ + 'Reyes Magos' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-01-06')), + 'Día de San José' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-03-19')), + 'San Pedro y San Pablo' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-06-29')), + 'Asunción de la Virgen' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-08-15')), + 'Día de la raza' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-10-12')), + 'Todos los santos' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-11-01')), + 'Independencia de Cartagena' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-11-11')), + 'Jueves Santo' => $easter->subDays(3), + 'Viernes Santo' => $easter->subDays(2), + 'Ascención de Jesús' => $easter->addDays(43), + 'Corpus Christi' => $easter->addDays(64), + 'Sagrado corazón de Jesús' => $easter->addDays(71), + + ]; + } + + /** @return CarbonImmutable */ + private function emilianiHoliday(CarbonImmutable $date): CarbonImmutable + { + if ($date->is('Monday')) { + return $date; + } else { + return $date->next('Monday'); + } + } +} diff --git a/tests/.pest/snapshots/Countries/ColombiaTest/it_can_calculate_colombia_holidays.snap b/tests/.pest/snapshots/Countries/ColombiaTest/it_can_calculate_colombia_holidays.snap new file mode 100644 index 000000000..38e611c25 --- /dev/null +++ b/tests/.pest/snapshots/Countries/ColombiaTest/it_can_calculate_colombia_holidays.snap @@ -0,0 +1,74 @@ +[ + { + "name": "A\u00f1o Nuevo", + "date": "2024-01-01" + }, + { + "name": "Reyes Magos", + "date": "2024-01-08" + }, + { + "name": "D\u00eda de San Jos\u00e9", + "date": "2024-03-25" + }, + { + "name": "Jueves Santo", + "date": "2024-03-28" + }, + { + "name": "Viernes Santo", + "date": "2024-03-29" + }, + { + "name": "D\u00eda del Trabajo", + "date": "2024-05-01" + }, + { + "name": "Ascenci\u00f3n de Jes\u00fas", + "date": "2024-05-13" + }, + { + "name": "Corpus Christi", + "date": "2024-06-03" + }, + { + "name": "Sagrado coraz\u00f3n de Jes\u00fas", + "date": "2024-06-10" + }, + { + "name": "San Pedro y San Pablo", + "date": "2024-07-01" + }, + { + "name": "D\u00eda de la independencia", + "date": "2024-07-20" + }, + { + "name": "Batalla de Boyac\u00e1", + "date": "2024-08-07" + }, + { + "name": "Asunci\u00f3n de la Virgen", + "date": "2024-08-19" + }, + { + "name": "D\u00eda de la raza", + "date": "2024-10-14" + }, + { + "name": "Todos los santos", + "date": "2024-11-04" + }, + { + "name": "Independencia de Cartagena", + "date": "2024-11-11" + }, + { + "name": "Inmaculada Concepci\u00f3n", + "date": "2024-12-08" + }, + { + "name": "Navidad", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/ColombiaTest.php b/tests/Countries/ColombiaTest.php new file mode 100644 index 000000000..f472f215c --- /dev/null +++ b/tests/Countries/ColombiaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 09da8be97c009fe384432103e776d34b7d667572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alvaro=20Le=C3=B3n=20Torres?= Date: Wed, 17 Jan 2024 19:16:06 -0500 Subject: [PATCH 2/5] Adding Colombia Holidays Added the Colombia's holidays. There's a situation with some holidays due to the "Emiliany Law" they are moved to the following monday. --- src/Countries/Colombia.php | 59 +++++++++++++++ .../it_can_calculate_colombia_holidays.snap | 74 +++++++++++++++++++ tests/Countries/ColombiaTest.php | 18 +++++ 3 files changed, 151 insertions(+) create mode 100644 src/Countries/Colombia.php create mode 100644 tests/.pest/snapshots/Countries/ColombiaTest/it_can_calculate_colombia_holidays.snap create mode 100644 tests/Countries/ColombiaTest.php diff --git a/src/Countries/Colombia.php b/src/Countries/Colombia.php new file mode 100644 index 000000000..1004e333f --- /dev/null +++ b/src/Countries/Colombia.php @@ -0,0 +1,59 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'Año Nuevo' => '01-01', + 'Día del Trabajo' => '05-01', + 'Día de la independencia' => '07-20', + 'Batalla de Boyacá' => '08-07', + 'Inmaculada Concepción' => '12-08', + 'Navidad' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('America/Bogota'); + + return [ + 'Reyes Magos' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-01-06')), + 'Día de San José' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-03-19')), + 'San Pedro y San Pablo' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-06-29')), + 'Asunción de la Virgen' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-08-15')), + 'Día de la raza' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-10-12')), + 'Todos los santos' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-11-01')), + 'Independencia de Cartagena' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-11-11')), + 'Jueves Santo' => $easter->subDays(3), + 'Viernes Santo' => $easter->subDays(2), + 'Ascención de Jesús' => $easter->addDays(43), + 'Corpus Christi' => $easter->addDays(64), + 'Sagrado corazón de Jesús' => $easter->addDays(71), + + ]; + } + + /** @return CarbonImmutable */ + private function emilianiHoliday(CarbonImmutable $date): CarbonImmutable + { + if ($date->is('Monday')) { + return $date; + } else { + return $date->next('Monday'); + } + } +} diff --git a/tests/.pest/snapshots/Countries/ColombiaTest/it_can_calculate_colombia_holidays.snap b/tests/.pest/snapshots/Countries/ColombiaTest/it_can_calculate_colombia_holidays.snap new file mode 100644 index 000000000..38e611c25 --- /dev/null +++ b/tests/.pest/snapshots/Countries/ColombiaTest/it_can_calculate_colombia_holidays.snap @@ -0,0 +1,74 @@ +[ + { + "name": "A\u00f1o Nuevo", + "date": "2024-01-01" + }, + { + "name": "Reyes Magos", + "date": "2024-01-08" + }, + { + "name": "D\u00eda de San Jos\u00e9", + "date": "2024-03-25" + }, + { + "name": "Jueves Santo", + "date": "2024-03-28" + }, + { + "name": "Viernes Santo", + "date": "2024-03-29" + }, + { + "name": "D\u00eda del Trabajo", + "date": "2024-05-01" + }, + { + "name": "Ascenci\u00f3n de Jes\u00fas", + "date": "2024-05-13" + }, + { + "name": "Corpus Christi", + "date": "2024-06-03" + }, + { + "name": "Sagrado coraz\u00f3n de Jes\u00fas", + "date": "2024-06-10" + }, + { + "name": "San Pedro y San Pablo", + "date": "2024-07-01" + }, + { + "name": "D\u00eda de la independencia", + "date": "2024-07-20" + }, + { + "name": "Batalla de Boyac\u00e1", + "date": "2024-08-07" + }, + { + "name": "Asunci\u00f3n de la Virgen", + "date": "2024-08-19" + }, + { + "name": "D\u00eda de la raza", + "date": "2024-10-14" + }, + { + "name": "Todos los santos", + "date": "2024-11-04" + }, + { + "name": "Independencia de Cartagena", + "date": "2024-11-11" + }, + { + "name": "Inmaculada Concepci\u00f3n", + "date": "2024-12-08" + }, + { + "name": "Navidad", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/ColombiaTest.php b/tests/Countries/ColombiaTest.php new file mode 100644 index 000000000..f472f215c --- /dev/null +++ b/tests/Countries/ColombiaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 36c0b643383af85c4e718ffac712c8d986e054fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alvaro=20Le=C3=B3n=20Torres?= Date: Thu, 18 Jan 2024 11:28:46 -0500 Subject: [PATCH 3/5] Update Colombia.php Deleted the line as suggested by @Nielsvanpach --- src/Countries/Colombia.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Countries/Colombia.php b/src/Countries/Colombia.php index 1004e333f..8aa3d40b6 100644 --- a/src/Countries/Colombia.php +++ b/src/Countries/Colombia.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'co'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ From 77f331ce40fc25b47e0c6764a5ea363a072e4bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alvaro=20Le=C3=B3n=20Torres?= Date: Mon, 22 Jan 2024 17:13:42 -0500 Subject: [PATCH 4/5] Update Colombia.php --- src/Countries/Colombia.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Countries/Colombia.php b/src/Countries/Colombia.php index 8aa3d40b6..6bafabb76 100644 --- a/src/Countries/Colombia.php +++ b/src/Countries/Colombia.php @@ -30,13 +30,13 @@ protected function variableHolidays(int $year): array ->setTimezone('America/Bogota'); return [ - 'Reyes Magos' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-01-06')), - 'Día de San José' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-03-19')), - 'San Pedro y San Pablo' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-06-29')), - 'Asunción de la Virgen' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-08-15')), - 'Día de la raza' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-10-12')), - 'Todos los santos' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-11-01')), - 'Independencia de Cartagena' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-11-11')), + 'Reyes Magos' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-01-06')->setTimezone('America/Bogota')), + 'Día de San José' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-03-20')->setTimezone('America/Bogota')), + 'San Pedro y San Pablo' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-06-29')->setTimezone('America/Bogota')), + 'Asunción de la Virgen' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-08-15')->setTimezone('America/Bogota')), + 'Día de la raza' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-10-12')->setTimezone('America/Bogota')), + 'Todos los santos' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-11-01')->setTimezone('America/Bogota')), + 'Independencia de Cartagena' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-11-11')->setTimezone('America/Bogota')), 'Jueves Santo' => $easter->subDays(3), 'Viernes Santo' => $easter->subDays(2), 'Ascención de Jesús' => $easter->addDays(43), From ad5460c4e87eca39ab71af3198bdefad22aca142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alvaro=20Le=C3=B3n=20Torres?= Date: Tue, 23 Jan 2024 10:25:43 -0500 Subject: [PATCH 5/5] Added changes to Colombia.php and to the test file - Suggestions from @luisprmat were incorporated. - All the work of emiliani holiday generation was included into the emilianiHoliday method to achieve code readability - The order of the holidays was updated to ensure that the next emiliani holiday that appears can be included at the end of the list. - The test was updated because it's "colombian holidays" not "colombia holidays" --- src/Countries/Colombia.php | 26 +++++++++---------- ... it_can_calculate_colombian_holidays.snap} | 0 tests/Countries/ColombiaTest.php | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) rename tests/.pest/snapshots/Countries/ColombiaTest/{it_can_calculate_colombia_holidays.snap => it_can_calculate_colombian_holidays.snap} (100%) diff --git a/src/Countries/Colombia.php b/src/Countries/Colombia.php index 6bafabb76..e2430f76a 100644 --- a/src/Countries/Colombia.php +++ b/src/Countries/Colombia.php @@ -26,33 +26,33 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('America/Bogota'); + $easter = $this->easter($year); return [ - 'Reyes Magos' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-01-06')->setTimezone('America/Bogota')), - 'Día de San José' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-03-20')->setTimezone('America/Bogota')), - 'San Pedro y San Pablo' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-06-29')->setTimezone('America/Bogota')), - 'Asunción de la Virgen' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-08-15')->setTimezone('America/Bogota')), - 'Día de la raza' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-10-12')->setTimezone('America/Bogota')), - 'Todos los santos' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-11-01')->setTimezone('America/Bogota')), - 'Independencia de Cartagena' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-11-11')->setTimezone('America/Bogota')), 'Jueves Santo' => $easter->subDays(3), 'Viernes Santo' => $easter->subDays(2), 'Ascención de Jesús' => $easter->addDays(43), 'Corpus Christi' => $easter->addDays(64), 'Sagrado corazón de Jesús' => $easter->addDays(71), + 'Reyes Magos' => $this->emilianiHoliday($year, 1, 6), + 'Día de San José' => $this->emilianiHoliday($year, 3, 19), + 'San Pedro y San Pablo' => $this->emilianiHoliday($year, 6, 29), + 'Asunción de la Virgen' => $this->emilianiHoliday($year, 8, 15), + 'Día de la raza' => $this->emilianiHoliday($year, 10, 12), + 'Todos los santos' => $this->emilianiHoliday($year, 11, 1), + 'Independencia de Cartagena' => $this->emilianiHoliday($year, 11, 11), ]; } /** @return CarbonImmutable */ - private function emilianiHoliday(CarbonImmutable $date): CarbonImmutable + private function emilianiHoliday(int $year, int $month, int $day): CarbonImmutable { - if ($date->is('Monday')) { - return $date; + $dateObj = CarbonImmutable::createFromDate($year, $month, $day, 'America/Bogota')->startOfDay(); + if ($dateObj->is('Monday')) { + return $dateObj; } else { - return $date->next('Monday'); + return $dateObj->next('Monday'); } } } diff --git a/tests/.pest/snapshots/Countries/ColombiaTest/it_can_calculate_colombia_holidays.snap b/tests/.pest/snapshots/Countries/ColombiaTest/it_can_calculate_colombian_holidays.snap similarity index 100% rename from tests/.pest/snapshots/Countries/ColombiaTest/it_can_calculate_colombia_holidays.snap rename to tests/.pest/snapshots/Countries/ColombiaTest/it_can_calculate_colombian_holidays.snap diff --git a/tests/Countries/ColombiaTest.php b/tests/Countries/ColombiaTest.php index f472f215c..623ffd94b 100644 --- a/tests/Countries/ColombiaTest.php +++ b/tests/Countries/ColombiaTest.php @@ -5,7 +5,7 @@ use Carbon\CarbonImmutable; use Spatie\Holidays\Holidays; -it('can calculate colombia holidays', function () { +it('can calculate colombian holidays', function () { CarbonImmutable::setTestNowAndTimezone('2024-01-01'); $holidays = Holidays::for(country: 'co')->get();