From ffe24af83fbb96ef25adccdc387d62ad287c7ffe Mon Sep 17 00:00:00 2001 From: Victor Allen Date: Thu, 10 Oct 2024 12:54:46 +0300 Subject: [PATCH] feat: Add dynamic October 10th holiday naming for Kenya - Introduced logic to dynamically calculate the name of the October 10th holiday based on the year: - Mazingira Day for 2024 and beyond - Utamaduni Day from 2022-2023 - Huduma Day from 2019-2021 - Moi Day for 2018 and earlier - Updated test cases to validate holiday names across different years. --- src/Countries/Kenya.php | 13 +++- ...er_10th_holiday_as_Huduma_Day_in_2021.snap | 42 +++++++++++++ ...10th_holiday_as_Mazingira_Day_in_2024.snap | 42 +++++++++++++ ...r_10th_holiday_as_Moi_Day_before_2019.snap | 42 +++++++++++++ ...10th_holiday_as_Utamaduni_Day_in_2023.snap | 42 +++++++++++++ tests/Countries/KenyaTest.php | 60 +++++++++++++++++++ 6 files changed, 240 insertions(+), 1 deletion(-) create mode 100644 tests/.pest/snapshots/Countries/KenyaTest/it_calculates_October_10th_holiday_as_Huduma_Day_in_2021.snap create mode 100644 tests/.pest/snapshots/Countries/KenyaTest/it_calculates_October_10th_holiday_as_Mazingira_Day_in_2024.snap create mode 100644 tests/.pest/snapshots/Countries/KenyaTest/it_calculates_October_10th_holiday_as_Moi_Day_before_2019.snap create mode 100644 tests/.pest/snapshots/Countries/KenyaTest/it_calculates_October_10th_holiday_as_Utamaduni_Day_in_2023.snap diff --git a/src/Countries/Kenya.php b/src/Countries/Kenya.php index 80d39579c..705dee567 100644 --- a/src/Countries/Kenya.php +++ b/src/Countries/Kenya.php @@ -17,7 +17,7 @@ protected function allHolidays(int $year): array "New Year's Day" => '01-01', 'Labour day' => '05-01', 'Madaraka Day' => '06-01', - 'Mazingira Day' => '10-10', + $this->getOctober10HolidayName($year) => '10-10', 'Mashujaa Day' => '10-20', 'Jamhuri Day' => '12-01', 'Christmas' => '12-25', @@ -35,4 +35,15 @@ protected function variableHolidays(int $year): array 'Easter Monday' => $easter->addDay(), ]; } + + /** @return string */ + protected function getOctober10HolidayName(int $year): string + { + return match (true) { + $year >= 2024 => 'Mazingira Day', + $year >= 2022 => 'Utamaduni Day', + $year >= 2019 => 'Huduma Day', + default => 'Moi Day' + }; + } } diff --git a/tests/.pest/snapshots/Countries/KenyaTest/it_calculates_October_10th_holiday_as_Huduma_Day_in_2021.snap b/tests/.pest/snapshots/Countries/KenyaTest/it_calculates_October_10th_holiday_as_Huduma_Day_in_2021.snap new file mode 100644 index 000000000..c74e189da --- /dev/null +++ b/tests/.pest/snapshots/Countries/KenyaTest/it_calculates_October_10th_holiday_as_Huduma_Day_in_2021.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2021-01-01" + }, + { + "name": "Good Friday", + "date": "2021-04-02" + }, + { + "name": "Easter Monday", + "date": "2021-04-05" + }, + { + "name": "Labour day", + "date": "2021-05-01" + }, + { + "name": "Madaraka Day", + "date": "2021-06-01" + }, + { + "name": "Huduma Day", + "date": "2021-10-10" + }, + { + "name": "Mashujaa Day", + "date": "2021-10-20" + }, + { + "name": "Jamhuri Day", + "date": "2021-12-01" + }, + { + "name": "Christmas", + "date": "2021-12-25" + }, + { + "name": "Boxing Day", + "date": "2021-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/KenyaTest/it_calculates_October_10th_holiday_as_Mazingira_Day_in_2024.snap b/tests/.pest/snapshots/Countries/KenyaTest/it_calculates_October_10th_holiday_as_Mazingira_Day_in_2024.snap new file mode 100644 index 000000000..4ef1f38b0 --- /dev/null +++ b/tests/.pest/snapshots/Countries/KenyaTest/it_calculates_October_10th_holiday_as_Mazingira_Day_in_2024.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Labour day", + "date": "2024-05-01" + }, + { + "name": "Madaraka Day", + "date": "2024-06-01" + }, + { + "name": "Mazingira Day", + "date": "2024-10-10" + }, + { + "name": "Mashujaa Day", + "date": "2024-10-20" + }, + { + "name": "Jamhuri Day", + "date": "2024-12-01" + }, + { + "name": "Christmas", + "date": "2024-12-25" + }, + { + "name": "Boxing Day", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/KenyaTest/it_calculates_October_10th_holiday_as_Moi_Day_before_2019.snap b/tests/.pest/snapshots/Countries/KenyaTest/it_calculates_October_10th_holiday_as_Moi_Day_before_2019.snap new file mode 100644 index 000000000..58f59b914 --- /dev/null +++ b/tests/.pest/snapshots/Countries/KenyaTest/it_calculates_October_10th_holiday_as_Moi_Day_before_2019.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2018-01-01" + }, + { + "name": "Good Friday", + "date": "2018-03-30" + }, + { + "name": "Easter Monday", + "date": "2018-04-02" + }, + { + "name": "Labour day", + "date": "2018-05-01" + }, + { + "name": "Madaraka Day", + "date": "2018-06-01" + }, + { + "name": "Moi Day", + "date": "2018-10-10" + }, + { + "name": "Mashujaa Day", + "date": "2018-10-20" + }, + { + "name": "Jamhuri Day", + "date": "2018-12-01" + }, + { + "name": "Christmas", + "date": "2018-12-25" + }, + { + "name": "Boxing Day", + "date": "2018-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/KenyaTest/it_calculates_October_10th_holiday_as_Utamaduni_Day_in_2023.snap b/tests/.pest/snapshots/Countries/KenyaTest/it_calculates_October_10th_holiday_as_Utamaduni_Day_in_2023.snap new file mode 100644 index 000000000..e6302a633 --- /dev/null +++ b/tests/.pest/snapshots/Countries/KenyaTest/it_calculates_October_10th_holiday_as_Utamaduni_Day_in_2023.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2023-01-01" + }, + { + "name": "Good Friday", + "date": "2023-04-07" + }, + { + "name": "Easter Monday", + "date": "2023-04-10" + }, + { + "name": "Labour day", + "date": "2023-05-01" + }, + { + "name": "Madaraka Day", + "date": "2023-06-01" + }, + { + "name": "Utamaduni Day", + "date": "2023-10-10" + }, + { + "name": "Mashujaa Day", + "date": "2023-10-20" + }, + { + "name": "Jamhuri Day", + "date": "2023-12-01" + }, + { + "name": "Christmas", + "date": "2023-12-25" + }, + { + "name": "Boxing Day", + "date": "2023-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/KenyaTest.php b/tests/Countries/KenyaTest.php index c5aef294d..a7ed187a6 100644 --- a/tests/Countries/KenyaTest.php +++ b/tests/Countries/KenyaTest.php @@ -16,3 +16,63 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); + +it('calculates October 10th holiday as Mazingira Day in 2024', function () { + CarbonImmutable::setTestNow('2024-10-10'); + + $holidays = Holidays::for(country: 'ke')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(findDate($holidays, 'Mazingira Day')) + ->toEqual(CarbonImmutable::create(2024, 10, 10)); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('calculates October 10th holiday as Utamaduni Day in 2023', function () { + CarbonImmutable::setTestNow('2023-10-10'); + + $holidays = Holidays::for(country: 'ke')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(findDate($holidays, 'Utamaduni Day')) + ->toEqual(CarbonImmutable::create(2023, 10, 10)); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('calculates October 10th holiday as Huduma Day in 2021', function () { + CarbonImmutable::setTestNow('2021-10-10'); + + $holidays = Holidays::for(country: 'ke')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(findDate($holidays, 'Huduma Day')) + ->toEqual(CarbonImmutable::create(2021, 10, 10)); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('calculates October 10th holiday as Moi Day before 2019', function () { + CarbonImmutable::setTestNow('2018-10-10'); + + $holidays = Holidays::for(country: 'ke')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(findDate($holidays, 'Moi Day')) + ->toEqual(CarbonImmutable::create(2018, 10, 10)); + + expect(formatDates($holidays))->toMatchSnapshot(); +});