Skip to content

Commit

Permalink
feat: Add dynamic October 10th holiday naming for Kenya
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
vamuigua committed Oct 10, 2024
1 parent 4cc92e3 commit ffe24af
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Countries/Kenya.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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'
};
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
]
Original file line number Diff line number Diff line change
@@ -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"
}
]
Original file line number Diff line number Diff line change
@@ -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"
}
]
Original file line number Diff line number Diff line change
@@ -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"
}
]
60 changes: 60 additions & 0 deletions tests/Countries/KenyaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

0 comments on commit ffe24af

Please sign in to comment.