From c74e36e0f51c52f679ef7792074381373df9805c Mon Sep 17 00:00:00 2001 From: AJ <60591772+devajmeireles@users.noreply.github.com> Date: Wed, 17 Jan 2024 11:53:50 -0300 Subject: [PATCH] code --- src/Countries/Brazil.php | 41 +++++++++++++++ .../it_can_calculate_brazil_holidays.snap | 50 +++++++++++++++++++ tests/Countries/BrazilTest.php | 18 +++++++ 3 files changed, 109 insertions(+) create mode 100644 src/Countries/Brazil.php create mode 100644 tests/.pest/snapshots/Countries/BrazilTest/it_can_calculate_brazil_holidays.snap create mode 100644 tests/Countries/BrazilTest.php diff --git a/src/Countries/Brazil.php b/src/Countries/Brazil.php new file mode 100644 index 000000000..7da5cc21e --- /dev/null +++ b/src/Countries/Brazil.php @@ -0,0 +1,41 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'Dia de Ano Novo' => '01-01', + 'Dia de Tiradentes' => '04-21', + 'Dia do Trabalhador' => '05-01', + 'Independência do Brasil' => '09-07', + 'Nossa Senhora Aparecida' => '10-12', + 'Finados' => '11-02', + 'Proclamação da República' => '11-15', + 'Natal' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('America/Sao_Paulo'); + + return [ + 'Páscoa' => $easter, + 'Carnaval' => $easter->subDays(47), + 'Sexta-feira Santa' => $easter->subDays(2), + 'Corpus Christi' => $easter->addDays(60), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/BrazilTest/it_can_calculate_brazil_holidays.snap b/tests/.pest/snapshots/Countries/BrazilTest/it_can_calculate_brazil_holidays.snap new file mode 100644 index 000000000..6e7675236 --- /dev/null +++ b/tests/.pest/snapshots/Countries/BrazilTest/it_can_calculate_brazil_holidays.snap @@ -0,0 +1,50 @@ +[ + { + "name": "Dia de Ano Novo", + "date": "2024-01-01" + }, + { + "name": "Carnaval", + "date": "2024-02-13" + }, + { + "name": "Sexta-feira Santa", + "date": "2024-03-29" + }, + { + "name": "P\u00e1scoa", + "date": "2024-03-31" + }, + { + "name": "Dia de Tiradentes", + "date": "2024-04-21" + }, + { + "name": "Dia do Trabalhador", + "date": "2024-05-01" + }, + { + "name": "Corpus Christi", + "date": "2024-05-30" + }, + { + "name": "Independ\u00eancia do Brasil", + "date": "2024-09-07" + }, + { + "name": "Nossa Senhora Aparecida", + "date": "2024-10-12" + }, + { + "name": "Finados", + "date": "2024-11-02" + }, + { + "name": "Proclama\u00e7\u00e3o da Rep\u00fablica", + "date": "2024-11-15" + }, + { + "name": "Natal", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/BrazilTest.php b/tests/Countries/BrazilTest.php new file mode 100644 index 000000000..91be74d40 --- /dev/null +++ b/tests/Countries/BrazilTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +});