Skip to content

Commit

Permalink
update(holiday): Utamaduni day renamed to Mazingira day (#245)
Browse files Browse the repository at this point in the history
* update(holiday): Utamaduni day renamed to Mazingira day

* Update holiday names to match the Public Holidays Act in Kenya

* 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.
  • Loading branch information
vamuigua authored Oct 10, 2024
1 parent cf5a22f commit ad8abf9
Show file tree
Hide file tree
Showing 7 changed files with 253 additions and 14 deletions.
25 changes: 18 additions & 7 deletions src/Countries/Kenya.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ public function countryCode(): string
protected function allHolidays(int $year): array
{
return array_merge([
"New Year's" => '01-01',
'Labour' => '05-01',
'Madaraka' => '06-01',
'Utamaduni' => '10-10',
'Mashujaa' => '10-20',
'Jamhuri' => '12-01',
"New Year's Day" => '01-01',
'Labour day' => '05-01',
'Madaraka Day' => '06-01',
$this->getOctober10HolidayName($year) => '10-10',
'Mashujaa Day' => '10-20',
'Jamhuri Day' => '12-01',
'Christmas' => '12-25',
'Boxing' => '12-26',
'Boxing Day' => '12-26',
], $this->variableHolidays($year));
}

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"
}
]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"name": "New Year's",
"name": "New Year's Day",
"date": "2024-01-01"
},
{
Expand All @@ -12,31 +12,31 @@
"date": "2024-04-01"
},
{
"name": "Labour",
"name": "Labour day",
"date": "2024-05-01"
},
{
"name": "Madaraka",
"name": "Madaraka Day",
"date": "2024-06-01"
},
{
"name": "Utamaduni",
"name": "Mazingira Day",
"date": "2024-10-10"
},
{
"name": "Mashujaa",
"name": "Mashujaa Day",
"date": "2024-10-20"
},
{
"name": "Jamhuri",
"name": "Jamhuri Day",
"date": "2024-12-01"
},
{
"name": "Christmas",
"date": "2024-12-25"
},
{
"name": "Boxing",
"name": "Boxing Day",
"date": "2024-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 ad8abf9

Please sign in to comment.