From 7b5b1e38c553d9f726c626f94e99e0b0da52cee8 Mon Sep 17 00:00:00 2001 From: "Hermann D. Schimpf" Date: Wed, 18 Dec 2024 17:17:36 -0300 Subject: [PATCH] Add new country `Paraguay` (#254) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * added `Paraguay` holidays class * Update comment * Added `Guaraní` translations * Updated tests for Guaraní lang * FIX: Guaraní translation --- lang/paraguay/en/holidays.json | 13 +++++ lang/paraguay/gn/holidays.json | 13 +++++ src/Countries/Paraguay.php | 55 +++++++++++++++++++ .../it_can_calculate_paraguayan_holidays.snap | 46 ++++++++++++++++ tests/Countries/ParaguayTest.php | 44 +++++++++++++++ 5 files changed, 171 insertions(+) create mode 100644 lang/paraguay/en/holidays.json create mode 100644 lang/paraguay/gn/holidays.json create mode 100644 src/Countries/Paraguay.php create mode 100644 tests/.pest/snapshots/Countries/ParaguayTest/it_can_calculate_paraguayan_holidays.snap create mode 100644 tests/Countries/ParaguayTest.php diff --git a/lang/paraguay/en/holidays.json b/lang/paraguay/en/holidays.json new file mode 100644 index 000000000..572d7835b --- /dev/null +++ b/lang/paraguay/en/holidays.json @@ -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" +} diff --git a/lang/paraguay/gn/holidays.json b/lang/paraguay/gn/holidays.json new file mode 100644 index 000000000..ba2998074 --- /dev/null +++ b/lang/paraguay/gn/holidays.json @@ -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" +} diff --git a/src/Countries/Paraguay.php b/src/Countries/Paraguay.php new file mode 100644 index 000000000..b5e33d712 --- /dev/null +++ b/src/Countries/Paraguay.php @@ -0,0 +1,55 @@ + '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 */ + 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); + } +} diff --git a/tests/.pest/snapshots/Countries/ParaguayTest/it_can_calculate_paraguayan_holidays.snap b/tests/.pest/snapshots/Countries/ParaguayTest/it_can_calculate_paraguayan_holidays.snap new file mode 100644 index 000000000..a21d3c4ec --- /dev/null +++ b/tests/.pest/snapshots/Countries/ParaguayTest/it_can_calculate_paraguayan_holidays.snap @@ -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" + } +] \ No newline at end of file diff --git a/tests/Countries/ParaguayTest.php b/tests/Countries/ParaguayTest.php new file mode 100644 index 000000000..343a122c9 --- /dev/null +++ b/tests/Countries/ParaguayTest.php @@ -0,0 +1,44 @@ +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], +]);