Skip to content

Commit

Permalink
Added Kenyan holidays (#69)
Browse files Browse the repository at this point in the history
* feat: kenyan holidays added

* added Utamaduni Day and Easter holidays

* fix:phpstan errors

* fix: removed buggy line
  • Loading branch information
PhilN8 authored Jan 27, 2024
1 parent 6649602 commit 0ed8208
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/Countries/Kenya.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class Kenya extends Country
{
public function countryCode(): string
{
return 'ke';
}

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",
"Christmas" => "12-25",
"Boxing" => "12-26",
], $this->variableHolidays($year));
}

/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$easter = CarbonImmutable::createFromTimestamp(easter_date($year))
->setTimezone('Africa/Nairobi');

return [
"Good Friday" => $easter->subDays(2),
"Easter Monday" => $easter->addDay(),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"name": "New Year's",
"date": "2024-01-01"
},
{
"name": "Good Friday",
"date": "2024-03-29"
},
{
"name": "Easter Monday",
"date": "2024-04-01"
},
{
"name": "Labour",
"date": "2024-05-01"
},
{
"name": "Madaraka",
"date": "2024-06-01"
},
{
"name": "Utamaduni",
"date": "2024-10-10"
},
{
"name": "Mashujaa",
"date": "2024-10-20"
},
{
"name": "Jamhuri",
"date": "2024-12-01"
},
{
"name": "Christmas",
"date": "2024-12-25"
},
{
"name": "Boxing",
"date": "2024-12-26"
}
]
18 changes: 18 additions & 0 deletions tests/Countries/KenyaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Spatie\Holidays\Tests\Countries;

use Carbon\CarbonImmutable;
use Spatie\Holidays\Holidays;

it('can calculate kenyan holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');

$holidays = Holidays::for(country: 'ke')->get();

expect($holidays)
->toBeArray()
->not()->toBeEmpty();

expect(formatDates($holidays))->toMatchSnapshot();
});

0 comments on commit 0ed8208

Please sign in to comment.